summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-06 17:45:13 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-12 16:54:51 +0100
commit165a2cb22597f7ee6c0b04e55f602539fc94e527 (patch)
tree1c003cfeff32273083b72b23a0ca7739fb2de4c5
parent850d1225f1666ab60c1d0b9d322a6683bc29dcdd (diff)
downloadpylint-git-165a2cb22597f7ee6c0b04e55f602539fc94e527.tar.gz
Add tests for crash on assignment expressions in if statemenpytts
-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