-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Help wanted 🙏Outside help would be appreciated, good for new contributorsOutside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementationpyreverseRelated to pyreverse componentRelated to pyreverse component
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
Metadata
Metadata
Assignees
Labels
Help wanted 🙏Outside help would be appreciated, good for new contributorsOutside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementationpyreverseRelated to pyreverse componentRelated to pyreverse component