summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.12.rst4
-rw-r--r--tests/functional/a/assign/assignment_expression.py17
3 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 34a5692bc..1fb2b9a88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -114,6 +114,10 @@ Release date: TBA
Closes #5222
+* ``pylint`` no longer crashes when checking assignment expressions within if-statements
+
+ Closes #5178
+
* Update ``literal-comparison``` checker to ignore tuple literals
Closes #3031
diff --git a/doc/whatsnew/2.12.rst b/doc/whatsnew/2.12.rst
index 760971a3a..76b08846f 100644
--- a/doc/whatsnew/2.12.rst
+++ b/doc/whatsnew/2.12.rst
@@ -73,6 +73,10 @@ Other Changes
* Fix ``install graphiz`` message which isn't needed for puml output format.
+* ``pylint`` no longer crashes when checking assignment expressions within if-statements
+
+ Closes #5178
+
* Fix ``simplify-boolean-expression`` when condition can be inferred as False.
Closes #5200
diff --git a/tests/functional/a/assign/assignment_expression.py b/tests/functional/a/assign/assignment_expression.py
index 3bf077b46..3bfb5d488 100644
--- a/tests/functional/a/assign/assignment_expression.py
+++ b/tests/functional/a/assign/assignment_expression.py
@@ -94,3 +94,20 @@ def func3():
# Lambda and IfExp
def func4():
l = lambda x: y if (y := x) else None
+
+
+# Crash related to assignment expression in nested if statements
+# See https://github.com/PyCQA/pylint/issues/5178
+def func5(val):
+ variable = None
+
+ if val == 1:
+ variable = "value"
+ if variable := "value":
+ pass
+
+ elif val == 2:
+ variable = "value_two"
+ variable = "value_two"
+
+ return variable