Skip to content

Commit

Permalink
Avoid regression for nodes defined and used in same line
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jan 29, 2022
1 parent 1b5d942 commit 53c5200
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,8 @@ def _check_consumer(
)
and node.name in node.root().locals
):
if defined_by_stmt:
current_consumer.mark_as_consumed(node.name, [node])
return (VariableVisitConsumerAction.CONTINUE, None)

elif base_scope_type != "lambda":
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/u/undefined/undefined_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def bad_default(var, default=unknown2): # [undefined-variable]
"""function with default arg's value set to an nonexistent name"""
print(var, default)
print(xxxx) # [undefined-variable]
augvar += 1 # [undefined-variable, unused-variable]
del vardel # [undefined-variable, unused-variable]
augvar += 1 # [undefined-variable]
del vardel # [undefined-variable]

LMBD = lambda x, y=doesnotexist: x+y # [undefined-variable]
LMBD2 = lambda x, y: x+z # [undefined-variable]
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/u/undefined/undefined_variable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ undefined-variable:23:8:23:20::Undefined variable '__revision__':UNDEFINED
undefined-variable:27:29:27:37:bad_default:Undefined variable 'unknown2':UNDEFINED
undefined-variable:30:10:30:14:bad_default:Undefined variable 'xxxx':UNDEFINED
undefined-variable:31:4:31:10:bad_default:Undefined variable 'augvar':UNDEFINED
unused-variable:31:4:31:10:bad_default:Unused variable 'augvar':UNDEFINED
undefined-variable:32:8:32:14:bad_default:Undefined variable 'vardel':UNDEFINED
unused-variable:32:8:32:14:bad_default:Unused variable 'vardel':UNDEFINED
undefined-variable:34:19:34:31:<lambda>:Undefined variable 'doesnotexist':UNDEFINED
undefined-variable:35:23:35:24:<lambda>:Undefined variable 'z':UNDEFINED
used-before-assignment:38:4:38:9::Using variable 'POUET' before assignment:CONTROL_FLOW
Expand Down

0 comments on commit 53c5200

Please sign in to comment.