Skip to content

Commit c70d618

Browse files
BANG-225: fix validation of multiple assignments
1 parent 3db7cd9 commit c70d618

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

flake8_variables_names/ast_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ def get_var_names_from_assignment(
1111
if isinstance(assignment_node.target, ast.Name):
1212
return [(assignment_node.target.id, assignment_node.target)]
1313
elif isinstance(assignment_node, ast.Assign):
14-
names = [t for t in assignment_node.targets if isinstance(t, ast.Name)]
14+
names = []
15+
for target in assignment_node.targets:
16+
if isinstance(target, ast.Name):
17+
names.append(target)
18+
elif isinstance(target, ast.Tuple):
19+
names.extend([dim for dim in target.dims if isinstance(dim, ast.Name)])
1520
return [(n.id, n) for n in names]
1621
return []
1722

tests/test_files/short_names.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
b = 1
33
c = 3
44
i = 4
5+
x, y, z = 5, 6, 7

tests/test_variables_names.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def test_ok_good_names():
1313

1414
def test_ok_for_short_names_file():
1515
errors = run_validator_for_test_file('short_names.py', use_strict_mode=True)
16-
assert len(errors) == 4
16+
assert len(errors) == 7
1717
errors = run_validator_for_test_file('short_names.py', use_strict_mode=False)
18-
assert len(errors) == 3
18+
assert len(errors) == 6
1919
assert (
2020
get_error_message(errors[0])
2121
== "VNE001 single letter variable names like 'a' are not allowed"

0 commit comments

Comments
 (0)