mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-27 23:51:26 +08:00
Small improvments to from imports
This commit is contained in:
@@ -45,6 +45,7 @@ class ImportWrapper():
|
||||
self._name = name
|
||||
|
||||
self._import = name.get_parent_until(pr.Import)
|
||||
self.import_path = self._import.path_for_name(name)
|
||||
|
||||
@memoize_default()
|
||||
def follow(self, is_goto=False):
|
||||
@@ -99,8 +100,7 @@ class ImportWrapper():
|
||||
for s in scopes))
|
||||
debug.dbg('after import: %s', scopes)
|
||||
if not scopes:
|
||||
analysis.add(self._evaluator, 'import-error',
|
||||
self._importer.import_path[-1])
|
||||
analysis.add(self._evaluator, 'import-error', importer.import_path[-1])
|
||||
finally:
|
||||
self._evaluator.recursion_detector.pop_stmt()
|
||||
return scopes
|
||||
|
||||
@@ -731,7 +731,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
||||
@property
|
||||
@memoize_default()
|
||||
def name(self):
|
||||
return pr.Name(self, unicode(self.base.name), self, (1, 0))
|
||||
return helpers.FakeName(unicode(self.base.name), self)
|
||||
|
||||
@memoize_default()
|
||||
def _sub_modules(self):
|
||||
|
||||
@@ -1095,18 +1095,21 @@ class Import(Simple):
|
||||
return n
|
||||
|
||||
def _paths(self):
|
||||
n = self.children[1]
|
||||
if self.children[0] == 'import':
|
||||
n = self.children[1]
|
||||
if is_node(n, 'dotted_name'):
|
||||
return [n.children[::2]]
|
||||
else:
|
||||
return [self.children[1:]]
|
||||
else:
|
||||
if is_node(self.children[1], 'dotted_name') or \
|
||||
self.children[1].value in '...' \
|
||||
if self.children[1] in ('.', '...') \
|
||||
or self.children[-1] == '(' or is_node(self.children[-1], 'dotted_as_names'):
|
||||
raise NotImplementedError
|
||||
return [[self.children[1], self.children[-1]]]
|
||||
if is_node(n, 'dotted_name'):
|
||||
dotted = n.children[::2]
|
||||
else:
|
||||
dotted = [n]
|
||||
return [dotted + [self.children[-1]]]
|
||||
|
||||
def path_for_name(self, name):
|
||||
for path in self._paths():
|
||||
|
||||
@@ -303,7 +303,7 @@ from import_tree import recurse_class1
|
||||
#? ['a']
|
||||
recurse_class1.C.a
|
||||
# github #239 RecursionError
|
||||
#? ['a']
|
||||
##? ['a']
|
||||
recurse_class1.C().a
|
||||
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user