Skip to content

Commit

Permalink
BANG-225: fix validation of multiple assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
pshishmarev-bestdoctor committed Jun 9, 2023
1 parent 3db7cd9 commit c70d618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion flake8_variables_names/ast_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ def get_var_names_from_assignment(
if isinstance(assignment_node.target, ast.Name):
return [(assignment_node.target.id, assignment_node.target)]
elif isinstance(assignment_node, ast.Assign):
names = [t for t in assignment_node.targets if isinstance(t, ast.Name)]
names = []
for target in assignment_node.targets:
if isinstance(target, ast.Name):
names.append(target)
elif isinstance(target, ast.Tuple):
names.extend([dim for dim in target.dims if isinstance(dim, ast.Name)])
return [(n.id, n) for n in names]
return []

Expand Down
1 change: 1 addition & 0 deletions tests/test_files/short_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
b = 1
c = 3
i = 4
x, y, z = 5, 6, 7
4 changes: 2 additions & 2 deletions tests/test_variables_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_ok_good_names():

def test_ok_for_short_names_file():
errors = run_validator_for_test_file('short_names.py', use_strict_mode=True)
assert len(errors) == 4
assert len(errors) == 7
errors = run_validator_for_test_file('short_names.py', use_strict_mode=False)
assert len(errors) == 3
assert len(errors) == 6
assert (
get_error_message(errors[0])
== "VNE001 single letter variable names like 'a' are not allowed"
Expand Down

0 comments on commit c70d618

Please sign in to comment.