Skip to content

Commit ab538b8

Browse files
jacobtylerwallsPierre-Sassoulas
authored andcommitted
Fix a crash when __all__ exists but cannot be inferred (#8741)
(cherry picked from commit 331e48f)
1 parent 7b1242c commit ab538b8

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

doc/whatsnew/fragments/8740.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash when ``__all__`` exists but cannot be inferred.
2+
3+
Closes #8740

pylint/checkers/variables.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,10 @@ def _check_module_attrs(
29822982
def _check_all(
29832983
self, node: nodes.Module, not_consumed: dict[str, list[nodes.NodeNG]]
29842984
) -> None:
2985-
assigned = next(node.igetattr("__all__"))
2985+
try:
2986+
assigned = next(node.igetattr("__all__"))
2987+
except astroid.InferenceError:
2988+
return
29862989
if isinstance(assigned, util.UninferableBase):
29872990
return
29882991
if assigned.pytype() not in {"builtins.list", "builtins.tuple"}:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Edge case: __all__ exists in module's locals, but cannot be inferred.
2+
3+
Other tests for undefined-all-variable in tests/functional/n/names_in__all__.py"""
4+
5+
__all__ += [] # [undefined-variable]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
undefined-variable:5:0:5:7::Undefined variable '__all__':UNDEFINED

0 commit comments

Comments
 (0)