summaryrefslogtreecommitdiff
path: root/astroid/interpreter
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-05-31 13:12:22 -0400
committerGitHub <noreply@github.com>2022-05-31 13:12:22 -0400
commit8bd9ff4a8bfbaf281987c8e05c863940716e1bb5 (patch)
treef7d7c3bb4a274e6f8df2fbd2497fa3a1062b5372 /astroid/interpreter
parent1ccb1c455b71bcf453253d996e3739f5153f2774 (diff)
downloadastroid-git-8bd9ff4a8bfbaf281987c8e05c863940716e1bb5.tar.gz
More conservative interpretation of `PathFinder.find_spec()` failures (#1581)
Diffstat (limited to 'astroid/interpreter')
-rw-r--r--astroid/interpreter/_import/util.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/astroid/interpreter/_import/util.py b/astroid/interpreter/_import/util.py
index 5db1702d..ab3aa652 100644
--- a/astroid/interpreter/_import/util.py
+++ b/astroid/interpreter/_import/util.py
@@ -34,8 +34,17 @@ def is_namespace(modname: str) -> bool:
working_modname, path=last_submodule_search_locations
)
except ValueError:
- # Assume it's a .pth file, unless it's __main__
- return modname != "__main__"
+ if modname == "__main__":
+ return False
+ try:
+ # .pth files will be on sys.modules
+ return sys.modules[modname].__spec__ is None
+ except KeyError:
+ return False
+ except AttributeError:
+ # Workaround for "py" module
+ # https://github.com/pytest-dev/apipkg/issues/13
+ return False
except KeyError:
# Intermediate steps might raise KeyErrors
# https://github.com/python/cpython/issues/93334