-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Ideas for new lints around iteration #7783
Comments
Thanks! One question -- given: # Not good
for x in a + b:
print(x) When would it be invalid to rewrite as |
If you are sure import numpy as np
a = b = np.matrix([[1,2], [3,4]])
for x in a + b:
print(x)
# [[2 4]]
# [[6 8]]
for x in itertools.chain(a, b):
print(x)
# [[1 2]]
# [[3 4]]
# [[1 2]]
# [[3 4]] |
Thanks, that makes sense. We do have the ability to do limited within-file inference for lists, tuples, sets, and dictionaries, with the downside that the inference can lead to false-negatives (but is a reasonable fit for rules like this). |
flake8-simplify or flake8-comprehensions may be interested in this rule as well. |
Idk how complete it is, but refurb added |
I apologize if you not looking for new lints to implement in Ruff.
I do a fair share of code reviews, and I quite often stumble on these issues which are not caught by any linter AFAICT (flake8, pylint, refurb, ruff). I am not sure how hard those would be to implement, as for the first one you would need some type inference.
This happens really often when people want to iterate on multiple lists, tuples, etc.
Another one in a similar spirit:
The text was updated successfully, but these errors were encountered: