diff options
-rw-r--r-- | pyflakes/checker.py | 8 | ||||
-rw-r--r-- | pyflakes/test/test_imports.py | 11 |
2 files changed, 14 insertions, 5 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 5af956c..1fbad48 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -542,7 +542,7 @@ class ExportBinding(Binding): can be determined statically, they will be treated as names for export and additional checking applied to them. - The only recognized C{__all__} assignment via list concatenation is in the + The only recognized C{__all__} assignment via list/tuple concatenation is in the following format: __all__ = ['a'] + ['b'] + ['c'] @@ -564,10 +564,10 @@ class ExportBinding(Binding): if isinstance(source.value, (ast.List, ast.Tuple)): _add_to_names(source.value) - # If concatenating lists + # If concatenating lists or tuples elif isinstance(source.value, ast.BinOp): currentValue = source.value - while isinstance(currentValue.right, ast.List): + while isinstance(currentValue.right, (ast.List, ast.Tuple)): left = currentValue.left right = currentValue.right _add_to_names(right) @@ -575,7 +575,7 @@ class ExportBinding(Binding): if isinstance(left, ast.BinOp): currentValue = left # If just two lists are being added - elif isinstance(left, ast.List): + elif isinstance(left, (ast.List, ast.Tuple)): _add_to_names(left) # All lists accounted for - done break diff --git a/pyflakes/test/test_imports.py b/pyflakes/test/test_imports.py index 13e7bef..d5be269 100644 --- a/pyflakes/test/test_imports.py +++ b/pyflakes/test/test_imports.py @@ -1084,7 +1084,7 @@ class TestSpecialAll(TestCase): __all__ += ['c', 'd'] ''', m.UndefinedExport, m.UndefinedExport) - def test_concatenationAssignment(self): + def test_list_concatenation_assignment(self): """ The C{__all__} variable is defined through list concatenation. """ @@ -1093,6 +1093,15 @@ class TestSpecialAll(TestCase): __all__ = ['a'] + ['b'] + ['c'] ''', m.UndefinedExport, m.UndefinedExport, m.UndefinedExport, m.UnusedImport) + def test_tuple_concatenation_assignment(self): + """ + The C{__all__} variable is defined through tuple concatenation. + """ + self.flakes(''' + import sys + __all__ = ('a',) + ('b',) + ('c',) + ''', m.UndefinedExport, m.UndefinedExport, m.UndefinedExport, m.UnusedImport) + def test_all_with_attributes(self): self.flakes(''' from foo import bar |