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

Crash ``AstroidError: IndexError: list index out of range'' #9945

Closed
edreamleo opened this issue Sep 21, 2024 · 6 comments · Fixed by pylint-dev/astroid#2574
Closed

Crash ``AstroidError: IndexError: list index out of range'' #9945

edreamleo opened this issue Sep 21, 2024 · 6 comments · Fixed by pylint-dev/astroid#2574
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@edreamleo
Copy link
Contributor

edreamleo commented Sep 21, 2024

Bug description

Crash when running pylint on leo/core/leoGlobals.py and leo\core\leoAst.py.

The files are too long to give here. You can find them both at
https://github.com/leo-editor/leo-editor/blob/devel/leo/core.

All Leo files are covered by the MIT license.

Configuration

C:\Users\Dev\.leo\.pylintrc available upon request.

Command used

pylint leo\core\leoGlobals.py

Equivalent to:

python -m pylint --rcfile C:\Users\Dev\.leo\.pylintrc %*

Pylint output

Traceback (most recent call last):
  File "C:\Python\Python3.12\Lib\site-packages\pylint\lint\pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "C:\Python\Python3.12\Lib\site-packages\pylint\lint\pylinter.py", line 1017, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python3.12\Lib\site-packages\pylint\lint\pylinter.py", line 1069, in _check_astroid_module
    walker.walk(node)
  File "C:\Python\Python3.12\Lib\site-packages\pylint\utils\ast_walker.py", line 90, in walk
    self.walk(child)
  File "C:\Python\Python3.12\Lib\site-packages\pylint\utils\ast_walker.py", line 90, in walk
    self.walk(child)
  File "C:\Python\Python3.12\Lib\site-packages\pylint\utils\ast_walker.py", line 87, in walk
    callback(astroid)
  File "C:\Python\Python3.12\Lib\site-packages\pylint\checkers\classes\special_methods_checker.py", line 183, in visit_functiondef
    inferred = _safe_infer_call_result(node, node)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python3.12\Lib\site-packages\pylint\checkers\classes\special_methods_checker.py", line 42, in _safe_infer_call_result
    value = next(inferit)
            ^^^^^^^^^^^^^
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 1658, in infer_call_result
    yield from returnnode.value.infer(context)
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4776, in _infer
    yield from self._infer_from_values(self.values, context)
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4787, in _infer_from_values
    for suffix in cls._infer_from_values(nodes[1:], context, **kwargs):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4787, in _infer_from_values
    for suffix in cls._infer_from_values(nodes[1:], context, **kwargs):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4787, in _infer_from_values
    for suffix in cls._infer_from_values(nodes[1:], context, **kwargs):
  [Previous line repeated 2 more times]
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4786, in _infer_from_values
    for prefix in nodes[0]._infer(context, **kwargs):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4683, in _infer
    for format_spec in self.format_spec.infer(context, **kwargs):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4776, in _infer
    yield from self._infer_from_values(self.values, context)
  File "C:\Python\Python3.12\Lib\site-packages\astroid\nodes\node_classes.py", line 4786, in _infer_from_values
    for prefix in nodes[0]._infer(context, **kwargs):
                  ~~~~~^^^
IndexError: list index out of range

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

Traceback (most recent call last):
  File "C:\Python\Python3.12\Lib\site-packages\pylint\lint\pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "C:\Python\Python3.12\Lib\site-packages\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.3.0
astroid 3.3.3

OS / Environment

Windows 11 AMD64 (build 10.0.22631) SP0
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
PyQt version 6.7.2
@edreamleo edreamleo added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 21, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 21, 2024
@edreamleo
Copy link
Contributor Author

edreamleo commented Sep 21, 2024

The crash persists after upgrading astroid and pylint. pip list:

Package                       Version
----------------------------- ----------------
alabaster                     0.7.16
astroid                       3.3.3
asttokens                     2.4.1
Babel                         2.15.0
beautifulsoup4                4.12.3
black                         24.4.2
build                         1.2.1
cachetools                    5.5.0
certifi                       2024.7.4
cffi                          1.16.0
chardet                       5.2.0
charset-normalizer            3.3.2
cli-ui                        0.17.2
click                         8.1.7
colorama                      0.4.6
contourpy                     1.2.1
contributors-txt              1.0.0
coverage                      7.6.0
cryptography                  43.0.0
cycler                        0.12.1
dialite                       0.5.3
dill                          0.3.8
distlib                       0.3.8
docopt                        0.6.2
docutils                      0.21.2
execnet                       2.1.1
filelock                      3.16.1
flexx                         0.8.4
fonttools                     4.53.1
gitdb                         4.0.11
GitPython                     3.1.43
idna                          3.7
imagesize                     1.4.1
importlib_metadata            8.2.0
iniconfig                     2.0.0
isort                         5.13.2
jaraco.classes                3.4.0
jaraco.context                5.3.0
jaraco.functools              4.0.1
jedi                          0.19.1
Jinja2                        3.1.4
keyring                       25.2.1
kiwisolver                    1.4.5
Markdown                      3.6
markdown-it-py                3.0.0
MarkupSafe                    2.1.5
matplotlib                    3.9.1
mccabe                        0.7.0
mdurl                         0.1.2
meta                          1.0.2
more-itertools                10.3.0
mypy                          1.11.0
mypy-extensions               1.0.0
nh3                           0.2.18
numpy                         2.0.1
packaging                     24.1
parso                         0.8.4
pathspec                      0.12.1
pillow                        10.4.0
pip                           24.2
pkginfo                       1.10.0
platformdirs                  4.2.2
pluggy                        1.5.0
pscript                       0.7.7
py                            1.11.0
py-cpuinfo                    9.0.0
pycparser                     2.22
pyenchant                     3.2.2
pyflakes                      3.2.0
Pygments                      2.18.0
pylint                        3.3.0
pyparsing                     3.1.2
pyproject-api                 1.8.0
pyproject_hooks               1.1.0
PyQt6                         6.7.1
PyQt6-QScintilla              2.14.1
PyQt6-Qt6                     6.7.2
PyQt6_sip                     13.8.0
PyQt6-WebEngine               6.7.0
PyQt6-WebEngine-Qt6           6.7.2
PyQt6-WebEngineSubwheel-Qt6   6.7.2
pytest                        8.3.2
pytest-benchmark              4.0.0
pytest-cov                    5.0.0
pytest-timeout                2.3.1
pytest-xdist                  3.6.1
python-dateutil               2.9.0.post0
pywin32-ctypes                0.2.2
readme_renderer               44.0
requests                      2.32.3
requests-toolbelt             1.0.0
rfc3986                       2.0.0
rich                          13.7.1
ruff                          0.5.5
schema                        0.7.7
Send2Trash                    1.8.3
setuptools                    75.1.0
six                           1.16.0
smmap                         5.0.1
snowballstemmer               2.2.0
soupsieve                     2.5
Sphinx                        7.4.7
sphinxcontrib-applehelp       1.0.8
sphinxcontrib-devhelp         1.0.6
sphinxcontrib-htmlhelp        2.0.6
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.8
sphinxcontrib-serializinghtml 1.1.10
tabulate                      0.8.10
tbump                         6.11.0
tk                            0.1.0
tomlkit                       0.11.8
tornado                       6.4.1
towncrier                     24.8.0
tox                           4.20.0
twine                         5.1.1
types-docutils                0.21.0.20240724
types-Markdown                3.6.0.20240316
types-paramiko                3.4.0.20240423
types-pkg-resources           0.1.3
types-PyYAML                  6.0.12.20240724
types-requests                2.32.0.20240712
types-six                     1.16.21.20240513
typing_extensions             4.12.2
Unidecode                     1.3.8
urllib3                       2.2.2
virtualenv                    20.26.5
webruntime                    0.5.8
windows-curses                2.3.3
zipp                          3.19.2

@edreamleo
Copy link
Contributor Author

edreamleo commented Sep 21, 2024

Reverting to pylint 3.2.7 solves the problem:

pip install --force-reinstall -v "pylint==3.2.7"

None of the following work for me:

pip install --force-reinstall -v "astroid==3.3.0"
pip install --force-reinstall -v "astroid==3.3.3"
pip install --force-reinstall -v "pylint==3.3.0"
pip install --force-reinstall -v "pylint==3.3.3"

@nickdrozd
Copy link
Collaborator

nickdrozd commented Sep 21, 2024

Reproducing example:

class A:
    def f(self):
        return f"{self.x:}"

Another:

class A:
    @staticmethod
    def f(x):
        return f"{x:}"

@edreamleo
Copy link
Contributor Author

@nickdrozd Thanks for the short examples!

@nickdrozd
Copy link
Collaborator

Perhaps the smallest reproducer of all:

_ = f"{x:}"

@edreamleo
Copy link
Contributor Author

@nickdrozd Thanks for the quick work!

Removing the empty format specifiers (they were unintentional cruft) allows pylint handles all of Leo's source without crashing.

pylint 3.3.0
astroid 3.3.3
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

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 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants