Skip to content

Crash tuple index out of range because of missing import #5789

@UncleOwen

Description

@UncleOwen

Bug description

When parsing the following file:
(Note that I'm missing the import for hypothesis.strategies.composite)

# These are tests. Do we really need docstrings?
# pylint: disable=missing-docstring

from typing import (
    Callable,
)


class AError(Exception):
    pass


class BError(Exception):
    pass


class CError(Exception):
    pass


@composite
def error_class(draw: Callable) -> BaseException:
    return draw(sampled_from((AError, BError, CError)))

pylint crashed with a IndexError and with the following stacktrace:

Traceback (most recent call last):
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1034, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1069, in _check_file
    check_astroid_module(ast_node)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1204, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module
    walker.walk(node)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/checkers/unsupported_version.py", line 63, in visit_decorators
    self._check_typing_final(node)
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/checkers/unsupported_version.py", line 77, in _check_typing_final
    for decorator in decorators or uninferable_final_decorators(node):
  File "/data/code/decoupled/.tox/py37/lib/python3.7/site-packages/pylint/checkers/utils.py", line 879, in uninferable_final_decorators
    import_node = decorator.lookup(decorator.name)[1][0]
IndexError: tuple index out of range

Configuration

[MASTER]
disable=locally-disabled

[TYPECHECK]
signature-mutators=decorator

Command used

.tox/py37/bin/pylint tests/test_foo.py

Pylint output

(see above)

Expected behavior

no crash

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.7.12 (default, Jan 15 2022, 18:42:10) 
[GCC 9.3.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

astroid==2.9.3
attrs==21.4.0
decorator==5.1.1
decoupled @ file:///data/code/decoupled/.tox/.tmp/package/1/decoupled-0.0.8.tar.gz
flake8==4.0.1
hypothesis==6.36.1
importlib-metadata==4.2.0
iniconfig==1.1.1
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.6.1
mypy==0.931
mypy-extensions==0.4.3
packaging==21.3
platformdirs==2.5.0
pluggy==1.0.0
py==1.11.0
pycodestyle==2.8.0
pyflakes==2.4.0
pylint==2.12.2
pyparsing==3.0.7
pytest==7.0.0
sortedcontainers==2.4.0
tblib==1.7.0
toml==0.10.2
tomli==2.0.1
typed-ast==1.5.2
types-decorator==5.1.4
typing_extensions==4.0.1
wrapt==1.13.3
zipp==3.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate 🐫Duplicate of an already existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions