Skip to content

Commit

Permalink
Check if the ModuleSpec origin is None to figure out if it is a names…
Browse files Browse the repository at this point in the history
…pace package

ModuleSpec.origin was changed in python/cpython#5481
to be None for namespace packages.
  • Loading branch information
PCManticore committed Jun 4, 2018
1 parent be874a9 commit a4996b4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4996b4

Please sign in to comment.