Skip to content

Commit

Permalink
Stop detecting modules compiled by cffi as namespace packages (#1777)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
jacobtylerwalls and Pierre-Sassoulas committed Sep 17, 2022
1 parent df941c1 commit b3f0ea7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
Expand Up @@ -12,6 +12,12 @@ What's New in astroid 2.12.10?
==============================
Release date: TBA


* Fixed a crash when introspecting modules compiled by `cffi`.

Closes #1776
Closes PyCQA/pylint#7399

* ``decorators.cached`` now gets its cache cleared by calling ``AstroidManager.clear_cache``.

Refs #1780
Expand Down
8 changes: 7 additions & 1 deletion astroid/interpreter/_import/util.py
Expand Up @@ -49,7 +49,13 @@ def is_namespace(modname: str) -> bool:
# .pth files will be on sys.modules
# __spec__ is set inconsistently on PyPy so we can't really on the heuristic here
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3736
return sys.modules[modname].__spec__ is None and not IS_PYPY
# Check first fragment of modname, e.g. "astroid", not "astroid.interpreter"
# because of cffi's behavior
# See: https://github.com/PyCQA/astroid/issues/1776
return (
sys.modules[processed_components[0]].__spec__ is None
and not IS_PYPY
)
except KeyError:
return False
except AttributeError:
Expand Down

0 comments on commit b3f0ea7

Please sign in to comment.