Skip to content

Commit 165a2cb

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Add tests for crash on assignment expressions in if statemenpytts
1 parent 850d122 commit 165a2cb

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ Release date: TBA
114114

115115
Closes #5222
116116

117+
* ``pylint`` no longer crashes when checking assignment expressions within if-statements
118+
119+
Closes #5178
120+
117121
* Update ``literal-comparison``` checker to ignore tuple literals
118122

119123
Closes #3031

doc/whatsnew/2.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ Other Changes
7373

7474
* Fix ``install graphiz`` message which isn't needed for puml output format.
7575

76+
* ``pylint`` no longer crashes when checking assignment expressions within if-statements
77+
78+
Closes #5178
79+
7680
* Fix ``simplify-boolean-expression`` when condition can be inferred as False.
7781

7882
Closes #5200

tests/functional/a/assign/assignment_expression.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ def func3():
9494
# Lambda and IfExp
9595
def func4():
9696
l = lambda x: y if (y := x) else None
97+
98+
99+
# Crash related to assignment expression in nested if statements
100+
# See https://github.com/PyCQA/pylint/issues/5178
101+
def func5(val):
102+
variable = None
103+
104+
if val == 1:
105+
variable = "value"
106+
if variable := "value":
107+
pass
108+
109+
elif val == 2:
110+
variable = "value_two"
111+
variable = "value_two"
112+
113+
return variable

0 commit comments

Comments
 (0)