Skip to content

Commit 1fae3de

Browse files
authored
ignore __all__ when not directly assigned (#675)
1 parent dbb1843 commit 1fae3de

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pyflakes/checker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,14 @@ def handleNodeStore(self, node):
12911291
parent_stmt != node._pyflakes_parent and
12921292
not self.isLiteralTupleUnpacking(parent_stmt)):
12931293
binding = Binding(name, node)
1294-
elif name == '__all__' and isinstance(self.scope, ModuleScope):
1294+
elif (
1295+
name == '__all__' and
1296+
isinstance(self.scope, ModuleScope) and
1297+
isinstance(
1298+
node._pyflakes_parent,
1299+
(ast.Assign, ast.AugAssign, ast.AnnAssign)
1300+
)
1301+
):
12951302
binding = ExportBinding(name, node._pyflakes_parent, self.scope)
12961303
elif PY2 and isinstance(getattr(node, 'ctx', None), ast.Param):
12971304
binding = Argument(name, self.getScopeNode(node))

pyflakes/test/test_imports.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,12 @@ class foo:
10571057
__all__ = ["bar"]
10581058
''', m.UnusedImport)
10591059

1060+
def test_ignored_when_not_directly_assigned(self):
1061+
self.flakes('''
1062+
import bar
1063+
(__all__,) = ("foo",)
1064+
''', m.UnusedImport)
1065+
10601066
def test_warningSuppressed(self):
10611067
"""
10621068
If a name is imported and unused but is named in C{__all__}, no warning

0 commit comments

Comments
 (0)