Skip to content

Commit 9b67845

Browse files
committed
Fix crash for consider-using-assignment-expr
1 parent f8f6ccd commit 9b67845

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix crash for ``consider-using-assignment-expr`` when a variable annotation without assignment
2+
is used as the ``if`` test expression.
3+
4+
Closes #10707

pylint/extensions/code_style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ def _check_consider_using_assignment_expr(self, node: nodes.If) -> None:
272272
if CodeStyleChecker._check_prev_sibling_to_if_stmt(
273273
prev_sibling, node_name.name
274274
):
275+
# Should ignore variable annotation without assignment
276+
if prev_sibling.value is None:
277+
return
278+
275279
# Check if match statement would be a better fit.
276280
# I.e. multiple ifs that test the same name.
277281
if CodeStyleChecker._check_ignore_assignment_expr_suggestion(

tests/functional/ext/code_style/cs_consider_using_assignment_expr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ class A:
157157
A.var = 2
158158
if A.var:
159159
...
160+
161+
162+
i: int
163+
if i: # pylint: disable=used-before-assignment
164+
pass

0 commit comments

Comments
 (0)