-
-
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
Report warning when dictionary or list is modified during iteration #2471
Comments
Thanks for creating an issue, but I don't think this is going to be that useful in the long run for all the folks. I suggest writing a third party plugin and release it to the public, if it's useful, we might consider adding it to the core as well. |
Thanks Claudiu, could you be more specific on details of your decision? This would help me to decide early on future Pylint contributions I had in mind. |
Disagree with this not being useful - came to file this as a feature request, but found this issue. It would have saved several hours debugging. |
Concretely, this would help prevent e.g. |
@esmail my understanding of Pylint's development policy is that it should remain a linter, capable of detecting syntax violations and relatively simple bugs. For realistic static analysis of Python code people should use different tools. |
Reopening because of:
@PCManticore I'm open to learning more about your vision on what should or should not end up in pylint, if I'm mistaken. Also we should probably triage the less useful checkers I merged if this one is not useful enough to make it in the code base (or at least remove them from the default checkers). |
See #6645: make sure to account for |
Wasn't this added with #5628? |
@DanielNoord is right, the code given as an example is raising a warning since 2.13.0:
I'm going to close, please open another issue for false negatives or false positive related to the |
@Pierre-Sassoulas Did you also check if we special-case |
Yes, it does not work #6648 😄 x = []
for i in x:
x = [1, 2, 3] Does not raise either. |
Created a branch with the initial patch : https://github.com/PyCQA/pylint/tree/first-patch-2471 |
#2471 (comment) is an interesting case, as I don't know whether it can lead to unexpected results at runtime. Bad style for sure, though. |
That sounds more like |
Well, and the norm for that msg (currently) is to not emit when overwriting names in the same namespace[0], so that's maybe a no-op. I'm tempted to re-close this. [0] -- it was the |
Thanks all -- if you find new cases to discuss, please open new issues. |
Is your feature request related to a problem? Please describe
A frequent bug which I see people running into is modifying list during iteration. Example bug from this stackoverflow question:
It would be great it if Pylint could detect this.
Describe the solution you'd like
Pylint should emit a warning when program modifies list or dictionary object while iterating over it.
Additional context
I've attached an example patch. For the following code
it reports
The patch obviously needs to be fixed/extended, I'd be happy to work on that if the project is interested in this feature.
0001-Initial-commit.patch.txt
The text was updated successfully, but these errors were encountered: