Opened 7 weeks ago
Closed 6 weeks 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
Reported by: | john-parton | Owned by: | john-parton |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
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 , 7 weeks ago
Has patch: | set |
---|
comment:2 by , 6 weeks ago
comment:3 by , 6 weeks 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