blob: e0d874ff885b15912f9c60b9187c1206557177d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
"""Tests for used-before-assignment with assignments in except handlers after
try blocks with return statements.
See: https://github.com/pylint-dev/pylint/issues/5500.
"""
# pylint: disable=inconsistent-return-statements
# Named expressions
def func_ok_namedexpr_1(var):
"""'msg' is defined in one handler with a named expression under an if."""
try:
return 1 / var.some_other_func()
except AttributeError:
if (msg := var.get_msg()):
pass
except ZeroDivisionError:
msg = "Division by 0"
print(msg)
def func_ok_namedexpr_2(var):
"""'msg' is defined in one handler with a named expression occurring
in a call used in an if test.
"""
try:
return 1 / var.some_other_func()
except AttributeError:
if print(msg := var.get_msg()):
pass
except ZeroDivisionError:
msg = "Division by 0"
print(msg)
def func_ok_namedexpr_3(var):
"""'msg' is defined in one handler with a named expression occurring
as a keyword in a call used in an if test.
"""
try:
return 1 / var.some_other_func()
except AttributeError:
if print("zero!", "here", sep=(msg := var.get_sep())):
pass
except ZeroDivisionError:
msg = "Division by 0"
print(msg)
|