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

pylint Crash with AstroidError "StatementMissing: Statement not found on" #9548

Closed
John-Robbins opened this issue Apr 13, 2024 · 2 comments
Closed
Labels
Invalid Not a bug, already exists or already fixed

Comments

@John-Robbins
Copy link

John-Robbins commented Apr 13, 2024

There were several other bug reports (#8210, #8079) but the first was on Windows, the second on Debian, but I'm on macOS Also, I was just starting a prototype of command line argument processing so the code for the crash is very simple.

(Thanks to all the contributors for pylint!)

Bug description

When parsing the following a.py:

"""A prototype."""

import argparse


class TestClass:
    """Something."""

    def do_the_args(self: "TestClass") -> None:
        """Something."""
        parser = argparse.ArgumentParser(description="XXXXXXXX")

        parser.add_argument("-c",
                            "--command",
                            action="store",
                            help="xxxxxx")
        parser.add_argument("-n",
                            "--nologo",
                            action="store_true",
                            help="xxxxx")
        parser.add_argument("program",
                            action="store",
                            help="xxxxx")
        args = parser.parse_args()

        print(f"command = {args.command}")
        print(f"nologo  = {args.nologo}")
        print(f"file    = {args.file}")


def main() -> None:
    """Something."""
    x: TestClass = TestClass()
    x.do_the_args()


if __name__ == "__main__":
    main()

Command used

pylint a.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 1017, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 1069, in _check_astroid_module
    walker.walk(node)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/checkers/variables.py", line 1642, in visit_name
    self._loopvar_name(node)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/checkers/variables.py", line 2544, in _loopvar_name
    if astmts[i].statement().parent_of(stmt) and not utils.in_for_else_branch(
       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johnrobbins/Code/tbp-venv/lib/python3.12/site-packages/astroid/nodes/node_ng.py", line 297, in statement
    return self.parent.statement()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/johnrobbins/Code/tbp-venv/lib/python3.12/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 414, in statement
    raise StatementMissing(target=self)
astroid.exceptions.StatementMissing: Statement not found on <Module.arg l.0 at 0x103599640>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/Users/johnrobbins/.vscode/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 790, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash.

Pylint version

pylint 3.0.2
astroid 3.1.0
Python 3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:38) [Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

darwin (Darwin)

Additional dependencies

I was running inside Visual Studio Code:
Version: 1.88.1 (Universal)
Commit: e170252f762678dec6ca2cc69aba1570769a5d39
Date: 2024-04-10T17:42:52.765Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin arm64 23.4.0

@jacobtylerwalls
Copy link
Member

Thanks, but I can't reproduce on pylint 3.1.0. Notice that pylint 3.0.2 is not compatible with astroid 3.1.0. astroid should never be upgraded by itself.

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@jacobtylerwalls jacobtylerwalls added the Invalid Not a bug, already exists or already fixed label Apr 15, 2024
@John-Robbins
Copy link
Author

No worries! Thanks so much for the pointer about the mismatch between pylint and astroid. Looks like I have something screwed up between Python and my home-brew installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, already exists or already fixed
Projects
None yet
Development

No branches or pull requests

2 participants