summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjack1142 <6032823+jack1142@users.noreply.github.com>2020-09-28 02:27:13 +0200
committerGitHub <noreply@github.com>2020-09-27 17:27:13 -0700
commitcdb0606c85a417e961129aa88ebee210481f730d (patch)
tree5cf23e33a32c9c366c11476a15a301e91a09ca84
parent2dce2ee2fe31357c5c5a080a6b4b63ea696b7f59 (diff)
downloadpyflakes-cdb0606c85a417e961129aa88ebee210481f730d.tar.gz
Extend F822 to support tuple concatenation (#544)
* Extend F822 to support tuple concatenation * Add test case * Use camel case
-rw-r--r--pyflakes/checker.py8
-rw-r--r--pyflakes/test/test_imports.py11
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