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 Building error when trying to create ast representation of module 'test' #7422

Closed
lucas-str opened this issue Sep 6, 2022 · 1 comment · Fixed by pylint-dev/astroid#1770
Assignees
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash Regression
Milestone

Comments

@lucas-str
Copy link

Bug description

With astroid 2.12.7, when parsing the following file:

from dataclasses import dataclass, InitVar


@dataclass
class TestClass:
    """Test Class"""

    config: InitVar = None

pylint crashed with a AstroidBuildingError and with the following stacktrace:

Traceback (most recent call last):
  File "/tmp/test/env/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 991, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/manager.py", line 117, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/builder.py", line 135, in file_build
    return self._post_build(module, builder, encoding)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/builder.py", line 161, in _post_build
    module = self._manager.visit_transforms(module)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/manager.py", line 94, in visit_transforms
    return self._transform.visit(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 89, in visit
    return self._visit(module)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 61, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 57, in _visit
    return self._transform(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 39, in _transform
    ret = transform_func(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/brain/brain_dataclasses.py", line 97, in dataclass_transform
    init_str = _generate_dataclass_init(
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/brain/brain_dataclasses.py", line 209, in _generate_dataclass_init
    param_str = f"{name}: {annotation.as_string()}"
AttributeError: 'NoneType' object has no attribute 'as_string'

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

Traceback (most recent call last):
  File "/tmp/test/env/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 690, in _get_asts
    ast_per_fileitem[fileitem] = self.get_ast(
  File "/tmp/test/env/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1010, in get_ast
    raise astroid.AstroidBuildingError(
astroid.exceptions.AstroidBuildingError: Building error when trying to create ast representation of module 'test'

Configuration

No response

Command used

pylint test.py

Pylint output

Traceback (most recent call last):
  File "/tmp/test/env/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 991, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/manager.py", line 117, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/builder.py", line 135, in file_build
    return self._post_build(module, builder, encoding)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/builder.py", line 161, in _post_build
    module = self._manager.visit_transforms(module)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/manager.py", line 94, in visit_transforms
    return self._transform.visit(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 89, in visit
    return self._visit(module)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 61, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 57, in _visit
    return self._transform(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/transforms.py", line 39, in _transform
    ret = transform_func(node)
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/brain/brain_dataclasses.py", line 97, in dataclass_transform
    init_str = _generate_dataclass_init(
  File "/tmp/test/env/lib/python3.9/site-packages/astroid/brain/brain_dataclasses.py", line 209, in _generate_dataclass_init
    param_str = f"{name}: {annotation.as_string()}"
AttributeError: 'NoneType' object has no attribute 'as_string'
************* Module test
test.py:1:0: F0002: test.py: Fatal error while checking 'test.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '.cache/pylint/pylint-crash-2022-09-06-14-25-21.txt'. (astroid-error)

Expected behavior

No crash.

Pylint version

pylint 2.15.0
astroid 2.12.7
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110]

OS / Environment

Debian 11.4

Additional dependencies

No response

@lucas-str lucas-str added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 6, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Astroid Related to astroid Regression Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 6, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.1 milestone Sep 6, 2022
@DanielNoord
Copy link
Collaborator

😡

Sorry @Pierre-Sassoulas, that seemed like a straight forward PR.

PR incoming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid Crash 💥 A bug that makes pylint crash Regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants