From a4a767f8bbbb2ddd2dbad60f3886e0eeb73ff75f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 18 Nov 2014 17:19:15 +0100 Subject: [PATCH] Import improvements. --- jedi/evaluate/imports.py | 4 ++-- jedi/parser/__init__.py | 1 + jedi/parser/representation.py | 38 +++++------------------------------ 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index bbf49595..b74c0cf2 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -513,7 +513,7 @@ class _Importer(object): Find a module with a path (of the module, like usb.backend.libusb10). """ def follow_str(ns_path, string): - debug.dbg('follow_module %s %s', ns_path, string) + debug.dbg('follow_module %s in %s', string, ns_path) path = None if ns_path: path = ns_path @@ -523,7 +523,7 @@ class _Importer(object): if path is not None: importing = find_module(string, [path]) else: - debug.dbg('search_module %s %s', string, self.file_path) + debug.dbg('search_module %s in %s', string, self.file_path) # Override the sys.path. It works only good that way. # Injecting the path directly into `find_module` did not work. sys.path, temp = sys_path, sys.path diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 88670843..fef6a2d6 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -95,6 +95,7 @@ class Parser(object): self.module = d.parse_string(source).get_parent_until() self.module.used_names = self.used_names + self.module.path = module_path self.module.set_global_names(self.global_names) def convert_node(self, grammar, type, children): diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index ca4b3249..0fcceba8 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -1061,38 +1061,6 @@ class ForFlow(Flow): class Import(Simple): - """ - Stores the imports of any Scopes. - - :param start_pos: Position (line, column) of the Import. - :type start_pos: tuple(int, int) - :param namespace_names: The import, can be empty if a star is given - :type namespace_names: list of Name - :param alias: The alias of a namespace(valid in the current namespace). - :type alias: list of Name - :param from_names: Like the namespace, can be equally used. - :type from_names: list of Name - :param star: If a star is used -> from time import *. - :type star: bool - :param defunct: An Import is valid or not. - :type defunct: bool - """ - def __init__old(self, module, start_pos, end_pos, namespace_names, alias=None, - from_names=(), star=False, relative_count=0, defunct=False): - super(Import, self).__init__(module, start_pos, end_pos) - - self.namespace_names = namespace_names - self.alias = alias - if self.alias: - alias.parent = self - self.from_names = from_names - for n in namespace_names + list(from_names): - n.parent = self.use_as_parent - - self.star = star - self.relative_count = relative_count - self.defunct = defunct - def get_defined_names(self): if self.children[0] == 'import': return self.children[1:] @@ -1126,7 +1094,11 @@ class Import(Simple): if self.children[0] == 'import': return [self.children[1:]] else: - raise NotImplementedError + if is_node(self.children[1], 'dotted_name') or \ + self.children[1].value in '...' \ + or self.children[-1] == '(' or is_node(self.children[-1], 'dotted_as_names'): + raise NotImplementedError + return [[self.children[1], self.children[-1]]] def path_for_name(self, name): for path in self._paths():