Skip to content

Commit cdb0606

Browse files
authored
Extend F822 to support tuple concatenation (#544)
* Extend F822 to support tuple concatenation * Add test case * Use camel case
1 parent 2dce2ee commit cdb0606

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pyflakes/checker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class ExportBinding(Binding):
542542
can be determined statically, they will be treated as names for export and
543543
additional checking applied to them.
544544
545-
The only recognized C{__all__} assignment via list concatenation is in the
545+
The only recognized C{__all__} assignment via list/tuple concatenation is in the
546546
following format:
547547
548548
__all__ = ['a'] + ['b'] + ['c']
@@ -564,18 +564,18 @@ def _add_to_names(container):
564564

565565
if isinstance(source.value, (ast.List, ast.Tuple)):
566566
_add_to_names(source.value)
567-
# If concatenating lists
567+
# If concatenating lists or tuples
568568
elif isinstance(source.value, ast.BinOp):
569569
currentValue = source.value
570-
while isinstance(currentValue.right, ast.List):
570+
while isinstance(currentValue.right, (ast.List, ast.Tuple)):
571571
left = currentValue.left
572572
right = currentValue.right
573573
_add_to_names(right)
574574
# If more lists are being added
575575
if isinstance(left, ast.BinOp):
576576
currentValue = left
577577
# If just two lists are being added
578-
elif isinstance(left, ast.List):
578+
elif isinstance(left, (ast.List, ast.Tuple)):
579579
_add_to_names(left)
580580
# All lists accounted for - done
581581
break

pyflakes/test/test_imports.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def test_augmentedAssignment(self):
10841084
__all__ += ['c', 'd']
10851085
''', m.UndefinedExport, m.UndefinedExport)
10861086

1087-
def test_concatenationAssignment(self):
1087+
def test_list_concatenation_assignment(self):
10881088
"""
10891089
The C{__all__} variable is defined through list concatenation.
10901090
"""
@@ -1093,6 +1093,15 @@ def test_concatenationAssignment(self):
10931093
__all__ = ['a'] + ['b'] + ['c']
10941094
''', m.UndefinedExport, m.UndefinedExport, m.UndefinedExport, m.UnusedImport)
10951095

1096+
def test_tuple_concatenation_assignment(self):
1097+
"""
1098+
The C{__all__} variable is defined through tuple concatenation.
1099+
"""
1100+
self.flakes('''
1101+
import sys
1102+
__all__ = ('a',) + ('b',) + ('c',)
1103+
''', m.UndefinedExport, m.UndefinedExport, m.UndefinedExport, m.UnusedImport)
1104+
10961105
def test_all_with_attributes(self):
10971106
self.flakes('''
10981107
from foo import bar

0 commit comments

Comments
 (0)