Skip to content

Commit 9f20e2a

Browse files
Divide into two cases so all that all lines are tested
1 parent 30717d8 commit 9f20e2a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/functional/u/use/used_before_assignment_issue2615.py

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ def main():
1010
res = opened_file.readlines()
1111
except ZeroDivisionError:
1212
print(res) # [used-before-assignment]
13+
print(res)
14+
15+
16+
def nested_except_blocks():
17+
"""Don't confuse except blocks with each other."""
18+
try:
19+
res = 1 / 0
20+
res = 42
21+
if main():
22+
res = None
23+
with open(__file__, encoding="utf-8") as opened_file:
24+
res = opened_file.readlines()
25+
except ZeroDivisionError:
1326
try:
1427
more_bad_division = 1 / 0
1528
except ZeroDivisionError:
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
used-before-assignment:12:14:12:17:main:Using variable 'res' before assignment:UNDEFINED
2-
used-before-assignment:16:18:16:35:main:Using variable 'more_bad_division' before assignment:UNDEFINED
2+
used-before-assignment:29:18:29:35:nested_except_blocks:Using variable 'more_bad_division' before assignment:UNDEFINED

0 commit comments

Comments
 (0)