summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-02-17 15:35:07 -0500
committerGitHub <noreply@github.com>2022-02-17 21:35:07 +0100
commit3253f4bba04415f125132f281208ce538712ab34 (patch)
tree664f757cf6aef120591c1fe5b0f1cb13104b528a /tests/functional
parent67055f4221324a5aba057c0e7e3a5ffdc41a7e35 (diff)
downloadpylint-git-3253f4bba04415f125132f281208ce538712ab34.tar.gz
Fix #5112: Prevent `used-before-assignment` if named expression found first in container (#5812)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/u/undefined/undefined_variable_py38.py14
-rw-r--r--tests/functional/u/undefined/undefined_variable_py38.txt1
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/functional/u/undefined/undefined_variable_py38.py b/tests/functional/u/undefined/undefined_variable_py38.py
index 924eb4a43..01e0201a8 100644
--- a/tests/functional/u/undefined/undefined_variable_py38.py
+++ b/tests/functional/u/undefined/undefined_variable_py38.py
@@ -155,3 +155,17 @@ class Dummy:
dummy = Dummy(value=val if (val := 'something') else 'anything')
+
+def expression_in_ternary_operator_inside_container():
+ """Named expression in ternary operator: inside container"""
+ return [val2 if (val2 := 'something') else 'anything']
+
+
+def expression_in_ternary_operator_inside_container_tuple():
+ """Same case, using a tuple inside a 1-element list"""
+ return [(val3, val3) if (val3 := 'something') else 'anything']
+
+
+def expression_in_ternary_operator_inside_container_wrong_position():
+ """2-element list where named expression comes too late"""
+ return [val3, val3 if (val3 := 'something') else 'anything'] # [used-before-assignment]
diff --git a/tests/functional/u/undefined/undefined_variable_py38.txt b/tests/functional/u/undefined/undefined_variable_py38.txt
index 43a2b6829..4cce67ecc 100644
--- a/tests/functional/u/undefined/undefined_variable_py38.txt
+++ b/tests/functional/u/undefined/undefined_variable_py38.txt
@@ -5,3 +5,4 @@ undefined-variable:99:6:99:19::Undefined variable 'else_assign_2':INFERENCE
unused-variable:126:4:126:10:type_annotation_unused_after_comprehension:Unused variable 'my_int':UNDEFINED
used-before-assignment:134:10:134:16:type_annotation_used_improperly_after_comprehension:Using variable 'my_int' before assignment:HIGH
used-before-assignment:141:10:141:16:type_annotation_used_improperly_after_comprehension_2:Using variable 'my_int' before assignment:HIGH
+used-before-assignment:171:12:171:16:expression_in_ternary_operator_inside_container_wrong_position:Using variable 'val3' before assignment:HIGH