-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…hadows an outer one (#5630) * Add regression test for #4434. Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
- Loading branch information
1 parent
fffde57
commit 619d853
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Tests for except handlers that shadow outer except handlers or exceptions. | ||
See: https://github.com/PyCQA/pylint/issues/5370 | ||
""" | ||
|
||
try: | ||
pass | ||
except ImportError as err: | ||
try: | ||
pass | ||
except ImportError as err: # [redefined-outer-name] | ||
pass | ||
print(err) | ||
|
||
try: | ||
pass | ||
except ImportError as err: | ||
try: | ||
pass | ||
except ImportError as err2: | ||
pass | ||
print(err) | ||
|
||
try: | ||
try: | ||
pass | ||
except ImportError as err: | ||
pass | ||
except ImportError: | ||
try: | ||
pass | ||
except ImportError as err: | ||
pass | ||
print(err) | ||
|
||
|
||
try: | ||
try: | ||
pass | ||
except ImportError as err: | ||
pass | ||
except ImportError as err: | ||
try: | ||
pass | ||
except ImportError: | ||
pass | ||
print(err) | ||
|
||
try: | ||
pass | ||
except ImportError as err: | ||
try: | ||
pass | ||
except ImportError as err2: | ||
try: | ||
pass | ||
except ImportError as err: # [redefined-outer-name] | ||
pass | ||
print(err) | ||
|
||
|
||
class CustomException(Exception): | ||
"""https://github.com/PyCQA/pylint/issues/4434""" | ||
|
||
|
||
def func(): | ||
"""Override CustomException by except .. as ..""" | ||
try: | ||
raise CustomException('Test') # [used-before-assignment] | ||
# pylint:disable-next=invalid-name, unused-variable | ||
except IOError as CustomException: # [redefined-outer-name] | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
redefined-outer-name:11:4:12:12::Redefining name 'err' from outer scope (line 8):UNDEFINED | ||
redefined-outer-name:57:8:58:16::Redefining name 'err' from outer scope (line 51):UNDEFINED | ||
used-before-assignment:69:14:69:29:func:Using variable 'CustomException' before assignment:UNDEFINED | ||
redefined-outer-name:71:4:72:12:func:Redefining name 'CustomException' from outer scope (line 62):UNDEFINED |