Opened 5 months ago
Closed 5 months ago
#35893 closed Cleanup/optimization (duplicate)
Using list comprehension (instead of a generator) to any/all where the items are side-effect free is a performance error
Description ¶
When passing a generator to any()
or all()
, Python can perform short-circuit evaluation to avoid needless computation.
Directly passing a list using list-comprehension is generally not recommended, unless the list-comprehension has a side-effect (for example calling a method that sets attributes on an object)
There's at least one place in the code-base where it's safe to replace list comprehension with a generator and get the short-circuit optimization for "free."
Change History (3)
comment:1 by , 5 months ago
Has patch: | set |
---|
comment:2 by , 5 months ago
comment:3 by , 5 months ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
I will track this with #23968 and update the commit to Refs
Patch here https://github.com/django/django/pull/18770