Skip to content

Commit 331e48f

Browse files
Fix a crash when __all__ exists but cannot be inferred (#8741)
1 parent 33d3f22 commit 331e48f

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
@@ -3046,7 +3046,10 @@ def _check_module_attrs(
30463046
def _check_all(
30473047
self, node: nodes.Module, not_consumed: dict[str, list[nodes.NodeNG]]
30483048
) -> None:
3049-
assigned = next(node.igetattr("__all__"))
3049+
try:
3050+
assigned = next(node.igetattr("__all__"))
3051+
except astroid.InferenceError:
3052+
return
30503053
if isinstance(assigned, util.UninferableBase):
30513054
return
30523055
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)