summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-06-04 07:49:27 -0700
committerClaudiu Popa <pcmanticore@gmail.com>2018-06-04 07:49:27 -0700
commita4996b4ce7d2a1b651ae984ee3448b8913577c5f (patch)
tree866045efd74b361359984fb3c5f803a71f858a8a
parentbe874a94b81f2b9404722937f1ea0e105c3c034a (diff)
downloadastroid-git-a4996b4ce7d2a1b651ae984ee3448b8913577c5f.tar.gz
Check if the ModuleSpec origin is None to figure out if it is a namespace package
ModuleSpec.origin was changed in https://github.com/python/cpython/pull/5481 to be None for namespace packages.
-rw-r--r--astroid/interpreter/_import/spec.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py
index b328b74f..524a8b1a 100644
--- a/astroid/interpreter/_import/spec.py
+++ b/astroid/interpreter/_import/spec.py
@@ -160,8 +160,12 @@ class PathSpecFinder(Finder):
def find_module(self, modname, module_parts, processed, submodule_path):
spec = importlib.machinery.PathFinder.find_spec(modname, path=submodule_path)
if spec:
- location = spec.origin if spec.origin != 'namespace' else None
- module_type = ModuleType.PY_NAMESPACE if spec.origin == 'namespace' else None
+ # origin can be either a string on older Python versions
+ # or None in case it is a namespace package:
+ # https://github.com/python/cpython/pull/5481
+ is_namespace_pkg = spec.origin in ('namespace', None)
+ location = spec.origin if not is_namespace_pkg else None
+ module_type = ModuleType.PY_NAMESPACE if is_namespace_pkg else None
spec = ModuleSpec(name=spec.name, location=location,
origin=spec.origin, module_type=module_type,
submodule_search_locations=list(spec.submodule_search_locations