mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-18 01:45:02 +08:00
improved star import support preparation
This commit is contained in:
@@ -43,9 +43,11 @@ class NameFinder(object):
|
||||
if search_global:
|
||||
return get_names_of_scope(self._evaluator, self.scope, self.position)
|
||||
else:
|
||||
if isinstance(self.scope, er.Instance):
|
||||
return self.scope.scope_generator()
|
||||
else:
|
||||
try:
|
||||
# Use scope generators if parts of it (e.g. sub classes or star
|
||||
# imports).
|
||||
gen = self.scope.scope_generator
|
||||
except AttributeError:
|
||||
if isinstance(self.scope, er.Class):
|
||||
# classes are only available directly via chaining?
|
||||
# strange stuff...
|
||||
@@ -53,6 +55,8 @@ class NameFinder(object):
|
||||
else:
|
||||
names = _get_defined_names_for_position(self.scope, self.position)
|
||||
return iter([(self.scope, names)])
|
||||
else:
|
||||
return gen()
|
||||
|
||||
def filter_name(self, scope_generator):
|
||||
"""
|
||||
|
||||
@@ -239,6 +239,23 @@ class NestedImportModule(pr.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):
|
||||
"""
|
||||
Checks the evaluator caches first, which resembles the ``sys.modules``
|
||||
|
||||
Reference in New Issue
Block a user