summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-03-25 22:26:01 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-03-26 22:01:46 +0100
commit5d5f65727829240ffcb84b7be8c5d1e4dcefa0ed (patch)
tree0ae9399943f92317072710d3269a0e10729a7415 /tests
parent09dce027f430498ba9c42c9f6502401b72f5c255 (diff)
downloadpylint-git-5d5f65727829240ffcb84b7be8c5d1e4dcefa0ed.tar.gz
Improve handling of assignment expressions
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/a/assignment_expression.py21
-rw-r--r--tests/functional/a/assignment_expression.txt7
2 files changed, 25 insertions, 3 deletions
diff --git a/tests/functional/a/assignment_expression.py b/tests/functional/a/assignment_expression.py
index ed8400163..aa6a27874 100644
--- a/tests/functional/a/assignment_expression.py
+++ b/tests/functional/a/assignment_expression.py
@@ -8,6 +8,9 @@ else:
x = False
x = b if (b := True) else False
+x2: bool = b2 if (b2 := True) else False
+x3 = 0
+x3 += b3 if (b3 := 4) else 6
a = ["a ", "b ", "c "]
c = [text for el in a if (text := el.strip()) == "b"]
@@ -49,6 +52,24 @@ function = lambda: (
print(function())
+# https://github.com/PyCQA/pylint/issues/3763
+foo if (foo := 3 - 2) > 0 else 0 # [pointless-statement]
+
+
+# https://github.com/PyCQA/pylint/issues/4238
+l1 = f'The number {(count1 := 4)} ' \
+ f'is equal to {count1}'
+l2: str = (
+ f'The number {(count2 := 4)} '
+ f'is equal to {count2}'
+)
+l3 = "Hello "
+l3 += (
+ f'The number {(count3 := 4)} '
+ f'is equal to {count3}'
+)
+
+
# check wrong usage
assert err_a, (err_a := 2) # [used-before-assignment]
print(err_b and (err_b := 2)) # [used-before-assignment]
diff --git a/tests/functional/a/assignment_expression.txt b/tests/functional/a/assignment_expression.txt
index df472fdd2..1be4c1389 100644
--- a/tests/functional/a/assignment_expression.txt
+++ b/tests/functional/a/assignment_expression.txt
@@ -1,3 +1,4 @@
-used-before-assignment:53:7::Using variable 'err_a' before assignment
-used-before-assignment:54:6::Using variable 'err_b' before assignment
-used-before-assignment:56:13::Using variable 'err_d' before assignment
+pointless-statement:56:0::Statement seems to have no effect
+used-before-assignment:74:7::Using variable 'err_a' before assignment
+used-before-assignment:75:6::Using variable 'err_b' before assignment
+used-before-assignment:77:13::Using variable 'err_d' before assignment