Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The undefined variable '__all__' results in an inference failed #8740

Closed
xiaxinmeng opened this issue Jun 6, 2023 · 1 comment · Fixed by #8741
Closed

The undefined variable '__all__' results in an inference failed #8740

xiaxinmeng opened this issue Jun 6, 2023 · 1 comment · Fixed by #8741
Assignees
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@xiaxinmeng
Copy link

The undefined variable runners uses an undefined attributes __all__, pylint reports an inference failed. See the following example.

pylint_example.py

import sys
if sys.version_info >= (3, 7):
    __all__ += runners.__all__

The expected behavior:
Pylint does not crash.

The actual output:

>> pylint pylint_example.py
************* Module pylint_example
Desktop/pylint_example.py:19:0: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:56:0: C0304: Final newline missing (missing-final-newline)
Desktop/pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Desktop/pylint_example.py:55:4: E0602: Undefined variable '__all__' (undefined-variable)
Desktop/pylint_example.py:55:15: E0602: Undefined variable 'runners' (undefined-variable)
Exception on node <Module.pylint_example l.0 at 0x7f797324d190> in file '/home/xxm/Desktop/pylint_example.py'
Traceback (most recent call last):
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 96, in walk
    callback(astroid)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 1364, in leave_module
    self._check_all(node, not_consumed)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 3049, in _check_all
    assigned = next(node.igetattr("__all__"))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/bases.py", line 197, in _infer_stmts
    raise InferenceError(
astroid.exceptions.InferenceError: Inference failed for all members of [<AssignName.__all__ l.55 at 0x7f797324da10>].
Desktop/empirical_type_checker/bug_report/pylint_example.py:1:0: F0002: /home/xxm/Desktop/pylint_example.py: Fatal error while checking '/home/xxm/Desktop/pylint_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/xxm/.cache/pylint/pylint-crash-2023-06-07-00-29-01.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Test Environment:

Ubuntu 18.04,
CPython 3.11.3
Pylint: 3.0.0b1
astroid 3.0.0a3

@nickdrozd nickdrozd added the Crash 💥 A bug that makes pylint crash label Jun 6, 2023
@nickdrozd
Copy link
Collaborator

Smaller reproducing example:

__all__ += []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants