diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-03-25 22:26:01 +0100 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-03-26 22:01:46 +0100 |
commit | 5d5f65727829240ffcb84b7be8c5d1e4dcefa0ed (patch) | |
tree | 0ae9399943f92317072710d3269a0e10729a7415 /pylint/checkers | |
parent | 09dce027f430498ba9c42c9f6502401b72f5c255 (diff) | |
download | pylint-git-5d5f65727829240ffcb84b7be8c5d1e4dcefa0ed.tar.gz |
Improve handling of assignment expressions
Diffstat (limited to 'pylint/checkers')
-rw-r--r-- | pylint/checkers/variables.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 3d7eadc20..f9c1f0fe4 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -59,6 +59,7 @@ from astroid.context import InferenceContext from pylint.checkers import BaseChecker, utils from pylint.checkers.utils import is_postponed_evaluation_enabled +from pylint.constants import PY39_PLUS from pylint.interfaces import HIGH, INFERENCE, INFERENCE_FAILURE, IAstroidChecker from pylint.utils import get_global_option @@ -1410,7 +1411,15 @@ class VariablesChecker(BaseChecker): # same line as the function definition maybee0601 = False elif ( - isinstance(defstmt, astroid.Assign) + isinstance( + defstmt, + ( + astroid.Assign, + astroid.AnnAssign, + astroid.AugAssign, + astroid.Expr, + ), + ) and isinstance(defstmt.value, astroid.IfExp) and frame is defframe and defframe.parent_of(node) @@ -1433,6 +1442,18 @@ class VariablesChecker(BaseChecker): and defnode.col_offset < node.col_offset ) or (defnode.lineno < node.lineno) + or ( + # Issue in the `ast` module until py39 + # Nodes in a multiline string have the same lineno + # Could be false-positive without check + not PY39_PLUS + and defnode.lineno == node.lineno + and isinstance( + defstmt, + (astroid.Assign, astroid.AnnAssign, astroid.AugAssign), + ) + and isinstance(defstmt.value, astroid.JoinedStr) + ) ) ): # Expressions, with assignment expressions |