-
-
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
False positive redefined-outer-name
for variables bound to the exception in except clauses
#9671
Comments
redefined-outer-name
for variables bound to the exception in except clauses
…e defined in an exception-handling block which shares the same name as a local variable that has been defined in a function body. Closes pylint-dev#9671
@mbyrnepr2, this attempt: pylint/pylint/checkers/variables.py Lines 1523 to 1524 in 805663a
doesn't make much sense because the same behavior is observed when the order is reversed: # pylint: disable=missing-module-docstring, missing-function-docstring
try:
raise ValueError('outer')
except ValueError as e:
print(e)
def f():
try:
raise ValueError('inner')
except ValueError as e:
print(e)
Pylint should really understand that the variable from
As a side note, Pylint apparently doesn't understand explicit |
Thank you @MikhailRyazanov. That indeed makes plenty of sense! |
When there is a name defined in an exception-handling block which shares the same name as a local variable that has been defined in a function body. Check if the outer node is in the scope of an exception assignment and do not emit ``redefined-outer-name`` if that is the case. Closes #9671
When there is a name defined in an exception-handling block which shares the same name as a local variable that has been defined in a function body. Check if the outer node is in the scope of an exception assignment and do not emit ``redefined-outer-name`` if that is the case. Closes #9671 (cherry picked from commit 57ae027)
When there is a name defined in an exception-handling block which shares the same name as a local variable that has been defined in a function body. Check if the outer node is in the scope of an exception assignment and do not emit ``redefined-outer-name`` if that is the case. Closes #9671 (cherry picked from commit 57ae027) Co-authored-by: Mark Byrne <[email protected]>
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
Pylint must not complain about reusing variables bound to the exception in except clauses because they are in fact not defined outside the corresponding except clause (as can be seen by uncommenting the last line in the example).
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: