Skip to content

Commit

Permalink
Fix false positive invalid-all-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 13, 2021
1 parent 1dd231b commit 3a36f1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pylint/checkers/variables.py
Expand Up @@ -2013,15 +2013,16 @@ def _check_module_attrs(self, node, module, module_names):
return module
return None

def _check_all(self, node, not_consumed):
def _check_all(self, node: nodes.Module, not_consumed):
assigned = next(node.igetattr("__all__"))
if assigned is astroid.Uninferable:
return

if not isinstance(assigned, (nodes.Tuple, nodes.List, list, tuple)):
self.add_message("invalid-all-format", node=node)
if not assigned.pytype() in [
"builtins.list",
"builtins.tuple",
] and not isinstance(assigned, (nodes.Tuple, nodes.List, list, tuple)):
self.add_message("invalid-all-format", line=assigned.tolineno, node=node)
return

for elt in getattr(assigned, "elts", ()):
try:
elt_name = next(elt.infer())
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/i/invalid/invalid_all_format.txt
@@ -1 +1 @@
invalid-all-format:5:11::Invalid format for __all__, must be tuple or list
invalid-all-format:5:0::Invalid format for __all__, must be tuple or list:HIGH
7 changes: 7 additions & 0 deletions tests/functional/i/invalid/invalid_all_format_valid_6.py
@@ -0,0 +1,7 @@
"""Test valid __all__ format."""

# pylint: disable=import-error, unused-import

from foo import bar

__all__ = tuple(globals().keys())

0 comments on commit 3a36f1e

Please sign in to comment.