-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Suggestion to improve redefined-outer-name or to introduce a new rule #8646
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
Comments
Related issues & PRs:
Note that |
This one's tough! We'd need to distinguish this from the general case where reassigning a variable (for clarity?) is perfectly fine. x = apple or banana
x = x or candy Do you have an idea about what would distinguish these cases? |
Wasn't meaning to be dense. I take it the idea is that defining loop variables are special. Just wondering your thoughts. |
I opened #8663 as a starting point to explore how this could be implemented. What do you think of the approach taken there? |
I like it! Sorry for the delay in reviewing, we'd really like to get a report from the primer tool, and I haven't debugged why it's not working on your branch. I can fire it up locally on just a subset of packages if need be. |
Thank you for the feedback 😊 |
Uh oh!
There was an error while loading. Please reload this page.
Current problem
The following code may not print what you expect on the last line:
The issue comes from the
for
loop, where theerrors
loop variable shadows the previously defined list.The unexpected problem is that, on the last line,
errors
is now a 1-item list!There is this script output:
As far as I know, Pylint currently does not have any rule that detects this (tested using Pylint 2.17.3 & 3.0.0a6).
redefined-outer-name
for example, does not get triggered.Desired solution
First, I'd like to know what Pylint maintainers think to be the best approach:
redefined-outer-name
to cover thisAdditional context
There are some edge cases to consider when such case happens, where the definition of loop variable "erases" a variable in the current scope:
The text was updated successfully, but these errors were encountered: