mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-20 16:08:25 +08:00
Goto should not include imports that cannot be followed.
This commit is contained in:
@@ -305,7 +305,8 @@ class Evaluator(object):
|
||||
s = imports.ImportWrapper(self, name)
|
||||
for n in s.follow(is_goto=True):
|
||||
yield n
|
||||
yield name
|
||||
else:
|
||||
yield name
|
||||
|
||||
stmt = name.get_definition()
|
||||
par = name.parent
|
||||
@@ -340,7 +341,8 @@ class Evaluator(object):
|
||||
elif isinstance(par, (pr.Param, pr.Function, pr.Class)) and par.name is name:
|
||||
return [name]
|
||||
elif isinstance(stmt, pr.Import):
|
||||
return imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||
modules = imports.ImportWrapper(self, name).follow(is_goto=True)
|
||||
return list(resolve_implicit_imports(modules))
|
||||
elif par.type == 'dotted_name': # Is a decorator.
|
||||
index = par.children.index(name)
|
||||
if index > 0:
|
||||
|
||||
@@ -104,20 +104,23 @@ class ImportWrapper(pr.Base):
|
||||
|
||||
if from_import_name is not None:
|
||||
types = list(chain.from_iterable(
|
||||
self._evaluator.find_types(s, from_import_name, is_goto)
|
||||
self._evaluator.find_types(s, from_import_name, is_goto=is_goto)
|
||||
for s in types))
|
||||
if not types:
|
||||
importer = get_importer(self._evaluator,
|
||||
tuple(import_path + [from_import_name]),
|
||||
module, self._import.level)
|
||||
types, _ = importer.follow_file_system()
|
||||
# goto only accepts `Name`
|
||||
if is_goto:
|
||||
types = [s.name for s in types]
|
||||
else:
|
||||
# goto only accepts `Name`
|
||||
if is_goto:
|
||||
types = [s.name for s in types]
|
||||
|
||||
|
||||
|
||||
# goto only accepts `Name`
|
||||
if is_goto and not rest:
|
||||
types = [s.name for s in types]
|
||||
|
||||
"""
|
||||
# follow the rest of the import (not FS -> classes, functions)
|
||||
if rest:
|
||||
@@ -298,7 +301,7 @@ class _Importer(object):
|
||||
@memoize_default(NO_DEFAULT)
|
||||
def follow_file_system(self):
|
||||
if not self.import_path:
|
||||
return None, []
|
||||
return [], []
|
||||
modules = self._do_import(self.import_path, self.sys_path_with_modifications())
|
||||
return modules, []
|
||||
|
||||
@@ -413,6 +416,8 @@ class _Importer(object):
|
||||
else:
|
||||
debug.dbg('search_module %s in paths %s', module_name, paths)
|
||||
for path in paths:
|
||||
# At the moment we are only using one path. So this is
|
||||
# not important to be correct.
|
||||
module_file, module_path, is_pkg = \
|
||||
find_module(import_parts[-1], [path])
|
||||
else:
|
||||
|
||||
@@ -775,7 +775,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
||||
return name
|
||||
|
||||
def py__file__(self):
|
||||
return self._module.path
|
||||
return os.path.abspath(self._module.path)
|
||||
|
||||
def py__package__(self):
|
||||
if self._get_init_directory() is None:
|
||||
|
||||
@@ -179,7 +179,7 @@ def _get_paths_from_buildout_script(evaluator, buildout_script):
|
||||
cache.save_parser(buildout_script, p)
|
||||
return p.module
|
||||
|
||||
cached = cache.load_parser(buildout_script, None)
|
||||
cached = cache.load_parser(buildout_script)
|
||||
module = cached and cached.module or load(buildout_script)
|
||||
if not module:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user