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

[astroid-error] error when checking type comment like 'type: # comment' #7347

Closed
Ultimanecat opened this issue Aug 24, 2022 · 4 comments · Fixed by pylint-dev/astroid#1753
Closed
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@Ultimanecat
Copy link

Ultimanecat commented Aug 24, 2022

Bug description

Checking the following code would lead to an astroid-error:

a = 1 # type: # any comment

This is probably due to a bug in astroid.
In astroid.rebuilder: check_type_comment, when the type comment is parsed as an ast, comment results in a 0-sized body, which leads to an IndexError.

Configuration

No response

Command used

pylint test_crash.py

Pylint output

Traceback (most recent call last):
  File "d:\codecheck-python\codecheck-pylint13\pylint\lint\pylinter.py", line 1279, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\manager.py", line 102, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\builder.py", line 133, in file_build
    module, builder = self._data_build(data, modname, path)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\builder.py", line 191, in _data_build
    module = builder.visit_module(node, modname, node_file, package)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\rebuilder.py", line 279, in visit_module
    [self.visit(child, newnode) for child in node.body],
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\rebuilder.py", line 279, in <listcomp>
    [self.visit(child, newnode) for child in node.body],
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\rebuilder.py", line 624, in visit
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\rebuilder.py", line 825, in visit_assign
    type_annotation = self.check_type_comment(node, parent=newnode)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\astroid-2.11.5-py3.8.egg\astroid\rebuilder.py", line 761, in check_type_comment
    type_object = self.visit(type_comment_ast.body[0], parent=parent)
IndexError: list index out of range
************* Module test_crash
C:\Users\xxx\Desktop\test_crash.py:1:0: F0002: C:\Users\xxx\Desktop\test_crash.py: Fatal error while checking 'C:\Users\xxx\Desktop\test_crash.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in 'C:\Users\xxx\AppData\Local\pylint\pylint\Cache\pylint-crash-2022-08-24-10.txt'. (astroid-error)

Expected behavior

no crash, no error

Pylint version

pylint 2.13.9
astroid 2.11.5
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

@Ultimanecat Ultimanecat added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 24, 2022
@mbyrnepr2 mbyrnepr2 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 Aug 24, 2022
@mbyrnepr2
Copy link
Member

Thanks @Ultimanecat.

Also reproducible on:

pylint 2.15.0-a0
astroid 2.13.0-dev0

@DanielNoord
Copy link
Collaborator

Fixed with pylint-dev/astroid#1753.

@Pierre-Sassoulas Since this is a crash should we consider releasing another quick patch version of astroid to include this fix in the new pylint version?

@Pierre-Sassoulas
Copy link
Member

Astroid 2.12.4 was released with the fix 🎉

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.0 milestone Aug 25, 2022
@DanielNoord
Copy link
Collaborator

Thanks for releasing @Pierre-Sassoulas 😄

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