From 333338ea8ea9032f68819c6f00980220852b3e70 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 12 Aug 2021 19:10:15 +0200 Subject: [PATCH] Fix false-positive used-before-assignment with := in Return node --- ChangeLog | 4 ++++ pylint/checkers/variables.py | 1 + tests/functional/a/assign/assignment_expression.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2c90999d33..8bdec24c3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -114,6 +114,10 @@ Release date: TBA Closes #3839 +* Fix false-positive ``used-before-assignment`` with an assignment expression in a ``Return`` node + + Closes #4828 + What's New in Pylint 2.9.6? =========================== diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 7009bfd5ee..89d98067b8 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1464,6 +1464,7 @@ def _is_variable_violation( astroid.AnnAssign, astroid.AugAssign, astroid.Expr, + astroid.Return, ), ) and isinstance(defstmt.value, astroid.IfExp) diff --git a/tests/functional/a/assign/assignment_expression.py b/tests/functional/a/assign/assignment_expression.py index a2a586e536..4bb41f1a62 100644 --- a/tests/functional/a/assign/assignment_expression.py +++ b/tests/functional/a/assign/assignment_expression.py @@ -84,3 +84,8 @@ def func(): def func2(): return f'The number {(count := 4)} ' \ f'is equal to {count}' + + +# https://github.com/PyCQA/pylint/issues/4828 +def func3(): + return bar if (bar := "") else ""