Skip to content

pyreverse should check that klass is still ClassDef #9797

Open

Description

Ran into this when trying to use pyreverse, but I think this might be an astroid bug. It seems like the issue is that is_stdlib_module() expects a string module name, but in cases where the node is Uninferable then the special UninferableBase object returns self for almost all attribute access, including .name. This leads to confusing exceptions that are hard for a user to interpret.

Steps to reproduce

from astroid.util import Uninferable
from astroid.modutils import is_stdlib_module

# Example from pyreverse/diadefslib.py line 75:
# https://github.com/pylint-dev/pylint/blob/main/pylint/pyreverse/diadefslib.py#L75
node = Uninferable
is_stdlib_module(node.root().name)

Current behavior

Traceback (most recent call last):
  File "/home/bjmc/Sandbox/example.py", line 7, in <module>
    is_stdlib_module(node.root().name)
  File "/home/bjmc/.cache/pypoetry/virtualenvs/example-zPbyUnCb-py3.10/lib/python3.10/site-packages/astroid/modutils.py", line 524, in is_stdlib_module
    return modname.split(".")[0] in stdlib_module_names
TypeError: 'UninferableBase' object is not subscriptable

Expected behavior

return False (UninferableBase is not known to be in stdlib)

Astroid version

$ python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
3.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Help wanted 🙏Outside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationpyreverseRelated to pyreverse component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions