-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any/all short circuiting #426
Comments
Thanks for the suggestion. In the past I removed some rules that suggested using generators over comprehensions, because the increase in laziness is not always a 100% compatible change: https://github.com/adamchainz/flake8-comprehensions/blob/main/HISTORY.rst#340-2021-03-18 . In the case of Also generator expressions are not always faster. For small-ish collections, list comprehensions often win. I'd be open to having a set of default-disabled rules that one opts into though. Perhaps there could be a setting ("suggest-generators" or something) that users add with the understanding that semantics could change... Thoughts? |
Thanks for the useful pointers. The scope of C407 used to be much broader, considering all builtins - frequently resulting in false positives. For The choice for generator or comprehension should indeed be made consciously (and flake8-comprehensions should help with pointing that out). Opting-in and having a proper disclaimer seems like a great solution. Notes on performance, for future reference:
|
@adamchainz Here is some performance bench-marking specifically for any / all: https://www.katrin-affolter.ch/Programming/performance_of_all_and_any |
FYI for any who wants to use this rule, it's implemented in flake8-pie as PIE802. |
Thanks @Skylion007 , since i'ts implemented elsewhere I think we can close this. I think I'll avoid adding rules that change laziness to this plugin, it'll just be easier to maintain and understand. |
Actually there's a PR open, I think we cxan review and add this. |
There is one counter example here, but the potential speedups are potentially worth it: astral-sh/ruff#3259 (comment) |
The counterexample isn't for |
Description
List comprehension can postpone the evaluation of any/all, which can hurt performance for larger iterables. Surprisingly, this was not yet included here as rule.
Example:
From this answer
Proposal
Extend the current set of rules with C418 and C419 (any, all), similar to C403 and C404
The text was updated successfully, but these errors were encountered: