mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
improved star import support preparation
This commit is contained in:
@@ -43,9 +43,11 @@ class NameFinder(object):
|
|||||||
if search_global:
|
if search_global:
|
||||||
return get_names_of_scope(self._evaluator, self.scope, self.position)
|
return get_names_of_scope(self._evaluator, self.scope, self.position)
|
||||||
else:
|
else:
|
||||||
if isinstance(self.scope, er.Instance):
|
try:
|
||||||
return self.scope.scope_generator()
|
# Use scope generators if parts of it (e.g. sub classes or star
|
||||||
else:
|
# imports).
|
||||||
|
gen = self.scope.scope_generator
|
||||||
|
except AttributeError:
|
||||||
if isinstance(self.scope, er.Class):
|
if isinstance(self.scope, er.Class):
|
||||||
# classes are only available directly via chaining?
|
# classes are only available directly via chaining?
|
||||||
# strange stuff...
|
# strange stuff...
|
||||||
@@ -53,6 +55,8 @@ class NameFinder(object):
|
|||||||
else:
|
else:
|
||||||
names = _get_defined_names_for_position(self.scope, self.position)
|
names = _get_defined_names_for_position(self.scope, self.position)
|
||||||
return iter([(self.scope, names)])
|
return iter([(self.scope, names)])
|
||||||
|
else:
|
||||||
|
return gen()
|
||||||
|
|
||||||
def filter_name(self, scope_generator):
|
def filter_name(self, scope_generator):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -239,6 +239,23 @@ class NestedImportModule(pr.Module):
|
|||||||
self._module)
|
self._module)
|
||||||
|
|
||||||
|
|
||||||
|
class StarImportModule(pr.Module):
|
||||||
|
"""
|
||||||
|
Used if a module contains star imports.
|
||||||
|
"""
|
||||||
|
def __init__(self, module, star_import_modules):
|
||||||
|
self._module = module
|
||||||
|
self._star_import_modules = star_import_modules
|
||||||
|
|
||||||
|
def scope_generator(self):
|
||||||
|
yield self.module
|
||||||
|
for s in self._star_import_modules:
|
||||||
|
yield s
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return getattr(self._module, name)
|
||||||
|
|
||||||
|
|
||||||
def get_importer(evaluator, import_path, module, level=0):
|
def get_importer(evaluator, import_path, module, level=0):
|
||||||
"""
|
"""
|
||||||
Checks the evaluator caches first, which resembles the ``sys.modules``
|
Checks the evaluator caches first, which resembles the ``sys.modules``
|
||||||
|
|||||||
Reference in New Issue
Block a user