Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/10707.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix crash for ``consider-using-assignment-expr`` when a variable annotation without assignment
is used as the ``if`` test expression.

Closes #10707
4 changes: 4 additions & 0 deletions pylint/extensions/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def _check_consider_using_assignment_expr(self, node: nodes.If) -> None:
if CodeStyleChecker._check_prev_sibling_to_if_stmt(
prev_sibling, node_name.name
):
# Should ignore variable annotation without assignment
if prev_sibling.value is None:
return
Comment on lines +275 to +277
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be directly in _check_prev_sibling_to_if_stmt ?


# Check if match statement would be a better fit.
# I.e. multiple ifs that test the same name.
if CodeStyleChecker._check_ignore_assignment_expr_suggestion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ class A:
A.var = 2
if A.var:
...


i: int
if i: # pylint: disable=used-before-assignment
pass