-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
C409 now makes code slower #12912
Comments
Oh this is also similar to #10838 |
These changes are all in preview and so we can still decide to change them before stabilizing. If we revert that change, though, we should do the same for the list rule variants. I don’t feel strongly about it. I would also be open to making it configurable. Perhaps the setting should state whether the user prefers a comprehension or a generator, and enforce it one way or another? Or would the setting just ignore comprehensions? |
By list rule variant do you mean C410? I think that one is fine because it never introduces a generator comprehension. It's maybe more dangerous to enforce list comprehensions over generator comprehensions. Also for probably mostly theoretical memory reasons, despite the perf impact, people typically seem more eager to go from list -> generator than generator -> list. So maybe I lean towards a setting to leave list comprehensions alone. Or actually, maybe the slowening parts of C409 and C419 should be split into separate rules. The new rule that applies to comprehensions could then have a setting for whether you prefer list comprehensions or generator comprehensions (defaulting to generator). I think this would let everyone configure their ideal behaviour. |
Sorry, I misspoke. I thought there was a rule that changed: list([f(x) for x in foo]) To: list(f(x) for x in foo) But no, the fix there is |
I generally agree that this behavior should be configurable (or even removed). What do you think, @AlexWaygood? |
I agree that these should either be two rules (one that makes your code slower and one that doesn't), or one configurable rule (where the default is to only emit the recommendations that do not make your code slower). Some people prefer to always remove inner parentheses in calls like |
Introduced in #12657
tuple(i for i in range(10000))
is like 50% slower thantuple([i for i in range(10000)])
. I think it's still fine to have this as a lint, but it's now impossible to configure ruff to distinguish between the two.This is a thematically similar complaint to #8884
The text was updated successfully, but these errors were encountered: