pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

Crash `'Deprecated' object has no attribute '__dict__'` with `unsafe-load-any-extension` #8975

Open RuRo opened 1 year ago

RuRo commented 1 year ago

When parsing the following file (with --unsafe-load-any-extension=y):

from black import FileMode

pylint crashed with a AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 811, in _lint_file
    check_astroid_module(module)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1085, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1135, in _check_astroid_module
    walker.walk(node)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 94, in walk
    self.walk(child)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/checkers/variables.py", line 1939, in visit_importfrom
    self._check_module_attrs(node, module, name.split("."))
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/checkers/variables.py", line 2963, in _check_module_attrs
    module = next(module.getattr(name)[0].infer())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 171, in infer
    yield from self._infer(context=context, **kwargs)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 143, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 112, in wrapped
    for res in _func(node, context, **kwargs):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/bases.py", line 177, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 184, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 143, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 112, in wrapped
    for res in _func(node, context, **kwargs):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/bases.py", line 177, in _infer_stmts
    for inf in stmt.infer(context=context):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/nodes/node_ng.py", line 184, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 143, in raise_if_nothing_inferred
    yield next(generator)
          ^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/decorators.py", line 112, in wrapped
    for res in _func(node, context, **kwargs):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/inference.py", line 334, in infer_import_from
    module = self.do_import_module()
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/nodes/_base_nodes.py", line 146, in do_import_module
    return mymodule.import_module(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 530, in import_module
    return AstroidManager().ast_from_module_name(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/manager.py", line 221, in ast_from_module_name
    return self.ast_from_module(named_module, modname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/manager.py", line 328, in ast_from_module
    return AstroidBuilder(self).module_build(module, modname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/builder.py", line 101, in module_build
    node = self.inspect_build(module, modname=modname, path=path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/raw_building.py", line 404, in inspect_build
    self.object_build(node, module)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/raw_building.py", line 445, in object_build
    class_node = object_build_class(node, member, name)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/raw_building.py", line 208, in object_build_class
    return _base_class_object_build(node, member, basenames, localname=localname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/astroid/raw_building.py", line 316, in _base_class_object_build
    instdict = member().__dict__
               ^^^^^^^^^^^^^^^^^
AttributeError: 'Deprecated' object has no attribute '__dict__'

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

Traceback (most recent call last):
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 775, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/tmp/tmp.L5cHJHB1gm/.venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 813, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Output of pip freeze --all:

astroid==2.15.6
black==23.7.0
click==8.1.7
dill==0.3.7
isort==5.12.0
lazy-object-proxy==1.9.0
mccabe==0.7.0
mypy-extensions==1.0.0
packaging==23.1
pathspec==0.11.2
pip==22.3.1
platformdirs==3.10.0
pylint==2.17.5
setuptools==65.5.0
tomlkit==0.12.1
wrapt==1.15.0
Pierre-Sassoulas commented 1 year ago

Thank you for opening the issue, I can reproduce this both on main and pylint 2.17.5.

jacobtylerwalls commented 1 year ago

Predates 3.0, suggest removing the blocker label.