Skip to content
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

Catch same names for exceptions in nested try-except blocks #5370

Closed
birkenfeld opened this issue Nov 22, 2021 · 1 comment · Fixed by #5630
Closed

Catch same names for exceptions in nested try-except blocks #5370

birkenfeld opened this issue Nov 22, 2021 · 1 comment · Fixed by #5630
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@birkenfeld
Copy link

birkenfeld commented Nov 22, 2021

Current problem

Given this code

try:
    something
except Exception as err:
    try:
        something else
	except Exception as err:
		handle
	print(err)

Depending on whether the second except triggers, err will be undefined in the print statement.

Desired solution

Pylint should probably catch this and suggest to rename one of the err variables.

Additional context

No response

@birkenfeld birkenfeld added Enhancement ✨ Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 22, 2021
@jacobtylerwalls
Copy link
Member

Good candidate for redefined-outer-name.

jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Jan 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 3, 2022
Pierre-Sassoulas added a commit that referenced this issue Jan 3, 2022
…hadows an outer one (#5630)

* Add regression test for #4434.

Co-authored-by: Pierre Sassoulas <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
3 participants