Skip to content

Commit

Permalink
Fix a crash when __all__ exists but cannot be inferred (#8741)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Jun 6, 2023
1 parent 33d3f22 commit 331e48f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8740.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash when ``__all__`` exists but cannot be inferred.

Closes #8740
5 changes: 4 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3046,7 +3046,10 @@ def _check_module_attrs(
def _check_all(
self, node: nodes.Module, not_consumed: dict[str, list[nodes.NodeNG]]
) -> None:
assigned = next(node.igetattr("__all__"))
try:
assigned = next(node.igetattr("__all__"))
except astroid.InferenceError:
return
if isinstance(assigned, util.UninferableBase):
return
if assigned.pytype() not in {"builtins.list", "builtins.tuple"}:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Edge case: __all__ exists in module's locals, but cannot be inferred.
Other tests for undefined-all-variable in tests/functional/n/names_in__all__.py"""

__all__ += [] # [undefined-variable]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
undefined-variable:5:0:5:7::Undefined variable '__all__':UNDEFINED

0 comments on commit 331e48f

Please sign in to comment.