From f5ba6de38c16d7ae343d3e61cf579561cb90d593 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 25 Mar 2018 23:25:23 +0200 Subject: [PATCH] Cleanup the namespace lookups so that it also works for Python 3.7 --- jedi/_compatibility.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 5dd5fed8..451d17d6 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -35,23 +35,18 @@ class DummyFile(object): def find_module_py34(string, path=None, full_name=None): - implicit_namespace_pkg = False spec = None loader = None spec = importlib.machinery.PathFinder.find_spec(string, path) - if hasattr(spec, 'origin'): - origin = spec.origin - implicit_namespace_pkg = origin == 'namespace' + if spec is not None: + # We try to disambiguate implicit namespace pkgs with non implicit namespace pkgs + if not spec.has_location: + full_name = string if not path else full_name + implicit_ns_info = ImplicitNSInfo(full_name, spec.submodule_search_locations._path) + return None, implicit_ns_info, False - # We try to disambiguate implicit namespace pkgs with non implicit namespace pkgs - if implicit_namespace_pkg: - full_name = string if not path else full_name - implicit_ns_info = ImplicitNSInfo(full_name, spec.submodule_search_locations._path) - return None, implicit_ns_info, False - - # we have found the tail end of the dotted path - if hasattr(spec, 'loader'): + # we have found the tail end of the dotted path loader = spec.loader return find_module_py33(string, path, loader) @@ -355,11 +350,11 @@ def no_unicode_pprint(dct): print(re.sub("u'", "'", s)) -def print_to_stderr(string): +def print_to_stderr(*args): if is_py3: - eval("print(string, file=sys.stderr)") + eval("print(*args, file=sys.stderr)") else: - print >> sys.stderr, string + print >> sys.stderr, args def utf8_repr(func):