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 AttributeError: 'ClassDef' object has no attribute 'value' #7429

Closed
enkidulan opened this issue Sep 7, 2022 · 2 comments · Fixed by pylint-dev/astroid#1773
Closed
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@enkidulan
Copy link

Bug description

When parsing the following file:

# Third party runtime dependencies
from authomatic import Authomatic
from authomatic.adapters import WebObAdapter
from pyramid.httpexceptions import HTTPNotFound

# VG Stuff
from .. import interfaces


class IOauthHandler:
    def __init__(self, settings):
        self.config = {
            "google": {
                "class_": "authomatic.providers.oauth2.Google",
                "consumer_key": settings["auth.google.consumer_key"],
                "consumer_secret": settings["auth.google.consumer_secret"],
                "scope": [
                    "https://www.googleapis.com/auth/userinfo.profile",
                    "https://www.googleapis.com/auth/userinfo.email",
                ],
            },
        }
        self.authomatic = Authomatic(self.config, settings["auth.secret"])

    def login(self, provider_name, request, response):
        if provider_name not in self.config:
            raise HTTPNotFound

        adapter = WebObAdapter(request, response)
        result = self.authomatic.login(adapter, provider_name)
        return result


def includeme(config):
    settings = config.get_settings()
    config.register_service(IOauthHandler(settings), interfaces.ISocialLoginProvider)

Configuration

No response

Command used

pylint oauth.py

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:

Traceback (most recent call last):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/inference_tip.py", line 38, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function infer_named_tuple at 0x7f02f7341900>, <Call l.635 at 0x7f02eeb02fe0>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/brain/brain_namedtuple_enum.py", line 88, in infer_func_form
    attributes: list[str] = names.value.replace(",", " ").split()
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'ClassDef' object has no attribute 'value'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/checkers/utils.py", line 1344, in safe_infer
    value = next(infer_gen)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 169, in infer
    yield from self._infer(context=context, **kwargs)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/bases.py", line 165, in _infer_stmts
    for inf in stmt.infer(context=context):  # type: ignore[union-attr]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/bases.py", line 165, in _infer_stmts
    for inf in stmt.infer(context=context):  # type: ignore[union-attr]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/inference.py", line 319, in infer_import_from
    module = self.do_import_module()
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/_base_nodes.py", line 148, in do_import_module
    return mymodule.import_module(
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 521, in import_module
    return AstroidManager().ast_from_module_name(absmodname)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/manager.py", line 208, in ast_from_module_name
    return self.ast_from_file(found_spec.location, modname, fallback=False)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/manager.py", line 117, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/builder.py", line 135, in file_build
    return self._post_build(module, builder, encoding)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/builder.py", line 161, in _post_build
    module = self._manager.visit_transforms(module)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/manager.py", line 94, in visit_transforms
    return self._transform.visit(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 89, in visit
    return self._visit(module)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 61, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 57, in _visit
    return self._transform(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/transforms.py", line 38, in _transform
    if predicate is None or predicate(node):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/brain/brain_namedtuple_enum.py", line 570, in _is_enum_subclass
    for klass in cls.mro()
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3057, in mro
    return self._compute_mro(context=context)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3026, in _compute_mro
    inferred_bases = list(self._inferred_bases(context=context))
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3009, in _inferred_bases
    baseobj = next(
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 3009, in <genexpr>
    baseobj = next(
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/bases.py", line 165, in _infer_stmts
    for inf in stmt.infer(context=context):  # type: ignore[union-attr]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 182, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 139, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/decorators.py", line 108, in wrapped
    for res in _func(node, context, **kwargs):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/bases.py", line 165, in _infer_stmts
    for inf in stmt.infer(context=context):  # type: ignore[union-attr]
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/nodes/node_ng.py", line 159, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/inference_tip.py", line 45, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/brain/brain_namedtuple_enum.py", line 190, in infer_named_tuple
    class_node, name, attributes = infer_func_form(
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/brain/brain_namedtuple_enum.py", line 93, in infer_func_form
    fields = _get_namedtuple_fields(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/astroid/brain/brain_namedtuple_enum.py", line 542, in _get_namedtuple_fields
    container = next(node.args[1].infer())
IndexError: list index out of range

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

Traceback (most recent call last):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/lint/pylinter.py", line 769, in _lint_file
    check_astroid_module(module)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/lint/pylinter.py", line 1029, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/lint/pylinter.py", line 1079, in _check_astroid_module
    walker.walk(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 1476, in visit_assign
    self._append_context_managers_to_stack(node)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 1529, in _append_context_managers_to_stack
    inferred = utils.safe_infer(value.func)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/checkers/utils.py", line 1348, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError

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

Traceback (most recent call last):
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/lint/pylinter.py", line 734, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/home/enki/projects/vg/.venv/lib64/python3.10/site-packages/pylint/lint/pylinter.py", line 771, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError


### Expected behavior

expect pylint to not crash

### Pylint version

```shell
pylint 2.15.0
astroid 2.12.8
Python 3.10.6 (main, Aug  2 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)]

OS / Environment

fedora 36

Additional dependencies

alembic==1.8.1
astroid==2.12.8
async-generator==1.10
attrs==22.1.0
Authomatic==1.0.0
bandit==1.7.4
bcrypt==4.0.0
beautifulsoup4==4.11.1
black==22.8.0
CacheControl==0.12.11
cachetools==5.2.0
cachy==0.3.0
certifi==2022.6.15
cffi==1.15.1
Chameleon==3.10.1
charset-normalizer==2.1.1
cleo==1.0.0a5
click==8.1.3
cloudpickle==2.1.0
coverage==6.4.4
crashtest==0.3.1
cryptography==38.0.0
defusedxml==0.7.1
dill==0.3.5.1
distlib==0.3.6
docutils==0.19
doit==0.36.0
dulwich==0.20.45
fancycompleter==0.9.1
filelock==3.8.0
gitdb==4.0.9
GitPython==3.1.27
google-auth==2.11.0
greenlet==1.1.3
gunicorn==20.1.0
h11==0.13.0
html5lib==1.1
hupper==1.10.3
idna==3.3
importlib-metadata==4.12.0
iniconfig==1.1.1
isort==5.10.1
jaraco.classes==3.2.2
jeepney==0.8.0
Jinja2==3.1.2
jsonschema==4.15.0
keyring==23.9.0
lazy-object-proxy==1.7.1
lockfile==0.12.2
Mako==1.2.2
MarkupSafe==2.1.1
mccabe==0.7.0
more-itertools==8.14.0
msgpack==1.0.4
mypy-extensions==0.4.3
oauthlib==2.1.0
orjson==3.8.0
outcome==1.2.0
packaging==21.3
PasteDeploy==2.1.1
pathspec==0.10.1
pbr==5.10.0
pdbpp==0.10.3
pexpect==4.8.0
pkginfo==1.8.3
plaster==1.0
plaster-pastedeploy==0.7
platformdirs==2.5.2
pluggy==1.0.0
poetry==1.2.0
poetry-core==1.1.0
poetry-plugin-export==1.0.6
psycopg2-binary==2.9.3
ptyprocess==0.7.0
py==1.11.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
Pygments==2.13.0
pylev==1.4.0
pylint==2.15.0
pyOpenSSL==22.0.0
pyparsing==3.0.9
pyramid==2.0
pyramid-auto-env==0.1.2
pyramid-chameleon==0.3
pyramid-debugtoolbar==4.9
pyramid-jinja2==2.10
pyramid-mako==1.1.0
pyramid-oauthlib==0.4.2
pyramid-retry==2.1.1
pyramid-services==2.2
pyramid-tm==2.5
pyrepl==0.9.0
pyrsistent==0.18.1
PySocks==1.7.1
pytest==7.1.3
pytest-cov==3.0.0
pytest-splinter==3.3.1
python-json-logger==2.0.4
python3-openid==3.2.0
PyYAML==6.0
repoze.lru==0.7
requests==2.28.1
requests-toolbelt==0.9.1
rsa==4.9
SecretStorage==3.3.3
selenium==4.2.0
sentry-sdk==1.9.8
shellingham==1.5.0
shortuuid==1.0.9
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
splinter==0.17.0
SQLAlchemy==1.4.41
stevedore==4.0.0
tomli==2.0.1
tomlkit==0.11.4
transaction==3.0.1
translationstring==1.4
trio==0.21.0
trio-websocket==0.9.2
urllib3==1.26.12
urllib3-secure-extra==0.1.0
venusian==3.0.0
virtualenv==20.16.4
waitress==2.1.2
webencodings==0.5.1
WebOb==1.8.7
WebTest==3.0.0
wired==0.3
wmctrl==0.4
wrapt==1.14.1
wsproto==1.2.0
zipp==3.8.1
zope.deprecation==4.4.0
zope.interface==5.4.0
zope.sqlalchemy==1.6

@enkidulan enkidulan added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 7, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 7, 2022
@DanielNoord DanielNoord added Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Sep 7, 2022
@DanielNoord DanielNoord added this to the 2.15.2 milestone Sep 7, 2022
@DanielNoord
Copy link
Collaborator

Thanks for the report. A fix will be available after we release a new version of pylint and astroid.

@akaihola
Copy link

I still have this issue with this source file (a minimal non-real-life example):

class AnotherClass:
    ...


class Pylint7429:
    def foo(self):
        self.__class__, myvar = AnotherClass, "myvalue"
$ pylint --version
pylint 2.15.2
astroid 2.12.9
Python 3.8.13 (default, Mar 16 2022, 13:02:57) 
[GCC 11.3.0]
$ pylint /tmp/pylint7429.py
************* Module pylint7429
[...]
Exception on node <AssignAttr.__class__ l.7 at 0x7fb5f19060d0> in file '/tmp/pylint7429.py'
Traceback (most recent call last):
  File "pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "pylint/checkers/classes/class_checker.py", line 1556, in visit_assignattr
    self._check_invalid_class_object(node)
  File "pylint/checkers/classes/class_checker.py", line 1561, in _check_invalid_class_object
    inferred = safe_infer(node.parent.value)
  File "astroid/bases.py", line 134, in __getattr__
    return getattr(self._proxied, name)
AttributeError: 'ClassDef' object has no attribute 'value'
/tmp/pylint7429.py:1:0: F0002: /tmp/pylint7429.py: Fatal error while checking '/tmp/pylint7429.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/akaihola/.cache/pylint/pylint-crash-2022-09-15-14-06-01.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

I guess I'll file a separate issue about that.

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