-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false-positive 'used-before-assignment' for assignments in except…
… blocks following try blocks that return (#5506)
- Loading branch information
1 parent
e3e5aeb
commit 35254c2
Showing
5 changed files
with
55 additions
and
7 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
15 changes: 15 additions & 0 deletions
15
tests/functional/u/use/used_before_assignment_except_handler_for_try_with_return.py
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,15 @@ | ||
"""Tests for used-before-assignment with assignments in except handlers after | ||
try blocks with return statements. | ||
See: https://github.com/PyCQA/pylint/issues/5500. | ||
""" | ||
def function(): | ||
"""Assume except blocks execute if the try block returns.""" | ||
try: | ||
success_message = "success message" | ||
return success_message | ||
except ValueError: | ||
failure_message = "failure message" | ||
finally: | ||
print(failure_message) # [used-before-assignment] | ||
|
||
return failure_message |
1 change: 1 addition & 0 deletions
1
tests/functional/u/use/used_before_assignment_except_handler_for_try_with_return.txt
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 @@ | ||
used-before-assignment:13:14:13:29:function:Using variable 'failure_message' before assignment:UNDEFINED |