From 165a2cb22597f7ee6c0b04e55f602539fc94e527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sat, 6 Nov 2021 17:45:13 +0200 Subject: Add tests for crash on assignment expressions in if statemenpytts --- ChangeLog | 4 ++++ doc/whatsnew/2.12.rst | 4 ++++ tests/functional/a/assign/assignment_expression.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) 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 -- cgit v1.2.1