Skip to content

Pylint is crashing with astroid.exceptions.StatementMissing: Statement not found on <Module.builtins l.0 #8079

Description

@jooola

Bug description

Pylint is crashing with:

Exception on node <FunctionDef.license l.155 at 0x7fb37394e940> in file '....'
// ...
astroid.exceptions.StatementMissing: Statement not found on <Module.builtins l.0 at 0x7f97337e4b20>

The line of code that is crashing pylint is:

https://dev.funkwhale.audio/jooola/funkwhale/-/blob/pylint_bug_licence/api/funkwhale_api/music/factories.py#L155

When renaming licence to license_ pylint doesn't crash.

You can clone the branch and run pylint:

git clone -b pylint_bug_licence https://dev.funkwhale.audio/jooola/funkwhale
cd funkwhale/api
poetry install
poetry run pylint \
    --jobs=4 \
    --output-format=colorized \
    --recursive=true \
    funkwhale_api/music/factories.py

Configuration

[tool.pylint.master]
load-plugins = ["pylint_django"]
django-settings-module = "config.settings.testing"

[tool.pylint.messages_control]
disable = [
  "invalid-name",
  "missing-class-docstring",
  "missing-function-docstring",
  "missing-module-docstring",
]

[tool.pylint.design]
max-parents = 13

[tool.pylint.format]
max-line-length = 120

Command used

poetry run pylint \
    --jobs=4 \
    --output-format=colorized \
    --recursive=true \
    funkwhale_api/music/factories.py

Pylint output

2023-01-18 21:09:12,028 funkwhale_api.config INFO     Running with the following plugins enabled: funkwhale_api.contrib.scrobbler, funkwhale_api.contrib.listenbrainz, funkwhale_api.contrib.maloja
Exception on node <FunctionDef.license l.155 at 0x7fb37394e940> in file '/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/funkwhale_api/music/factories.py'
Traceback (most recent call last):
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 60, in __call__
    self.augmentation_func(Chain(self.old_method, node), node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 119, in __call__
    chain()
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 69, in __call__
    self.old_method(self.node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/checkers/classes/class_checker.py", line 1241, in visit_functiondef
    for obj in ancestor.lookup(node.name)[1]:
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 367, in lookup
    return self.scope().scope_lookup(self, name)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2340, in scope_lookup
    return frame._scope_lookup(node, name, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 86, in _scope_lookup
    return pscope.scope_lookup(node, name)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 380, in scope_lookup
    return self._scope_lookup(node, name, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 75, in _scope_lookup
    stmts = _filter_stmts(node, self.locals[name], self, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 105, in _filter_stmts
    statements = _get_filtered_node_statements(base_node, stmts)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 17, in _get_filtered_node_statements
    statements = [(node, node.statement(future=True)) for node in stmt_nodes]
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 17, in <listcomp>
    statements = [(node, node.statement(future=True)) for node in stmt_nodes]
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 324, in statement
    return self.parent.statement(future=future)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 470, in statement
    raise StatementMissing(target=self)
astroid.exceptions.StatementMissing: Statement not found on <Module.builtins l.0 at 0x7fb37c5bfb20>
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 831, in _check_file
    check_astroid_module(ast_node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1060, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1110, in _check_astroid_module
    walker.walk(node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 60, in __call__
    self.augmentation_func(Chain(self.old_method, node), node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 119, in __call__
    chain()
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint_plugin_utils/__init__.py", line 69, in __call__
    self.old_method(self.node)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/checkers/classes/class_checker.py", line 1241, in visit_functiondef
    for obj in ancestor.lookup(node.name)[1]:
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/node_classes.py", line 367, in lookup
    return self.scope().scope_lookup(self, name)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2340, in scope_lookup
    return frame._scope_lookup(node, name, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 86, in _scope_lookup
    return pscope.scope_lookup(node, name)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 380, in scope_lookup
    return self._scope_lookup(node, name, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/mixin.py", line 75, in _scope_lookup
    stmts = _filter_stmts(node, self.locals[name], self, offset)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 105, in _filter_stmts
    statements = _get_filtered_node_statements(base_node, stmts)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 17, in _get_filtered_node_statements
    statements = [(node, node.statement(future=True)) for node in stmt_nodes]
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/filter_statements.py", line 17, in <listcomp>
    statements = [(node, node.statement(future=True)) for node in stmt_nodes]
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/node_ng.py", line 324, in statement
    return self.parent.statement(future=future)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 470, in statement
    raise StatementMissing(target=self)
astroid.exceptions.StatementMissing: Statement not found on <Module.builtins l.0 at 0x7fb37c5bfb20>

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

Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/parallel.py", line 72, in _worker_check_single_file
    _worker_linter.check_single_file_item(file_item)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 743, in check_single_file_item
    self._check_file(self.get_ast, check_astroid_module, file)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 833, in _check_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError
"""

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

Traceback (most recent call last):
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/__init__.py", line 35, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/run.py", line 207, in __init__
    linter.check(args)
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 674, in check
    check_parallel(
  File "/home/jo/git/dev.funkwhale.audio/funkwhale/funkwhale/api/.venv/lib/python3.9/site-packages/pylint/lint/parallel.py", line 152, in check_parallel
    for (
  File "/usr/lib/python3.9/multiprocessing/pool.py", line 870, in next
    raise value
astroid.exceptions.AstroidError

Expected behavior

Pylint should print a linting error, instead of crashing.

Pylint version

$ poetry run pylint --version
pylint 2.15.6
astroid 2.13.2
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]

OS / Environment

Debian Bullseye

Additional dependencies

$ poetry show pylint
name : pylint
version : 2.15.6
description : python code static checker

dependencies

  • astroid >=2.12.12,<=2.14.0-dev0
  • colorama >=0.4.5
  • dill >=0.2
  • isort >=4.2.5,<6
  • mccabe >=0.6,<0.8
  • platformdirs >=2.2.0
  • tomli >=1.1.0
  • tomlkit >=0.10.1
  • typing-extensions >=3.10.0

required by

  • pylint-django >=2.0,<3
  • pylint-plugin-utils >=1.7

$ poetry show pylint-django
name : pylint-django
version : 2.5.3
description : A Pylint plugin to help Pylint understand the Django web framework

dependencies

  • pylint >=2.0,<3
  • pylint-plugin-utils >=0.7

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions