mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
fixed remainig problems with imports. detected with py3k
This commit is contained in:
13
functions.py
13
functions.py
@@ -240,6 +240,13 @@ def get_definition(source, line, column, source_path):
|
|||||||
:return: list of Definition objects, which are basically scopes.
|
:return: list of Definition objects, which are basically scopes.
|
||||||
:rtype: list
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
|
def resolve_import_paths(scopes):
|
||||||
|
for s in scopes.copy():
|
||||||
|
if isinstance(s, imports.ImportPath):
|
||||||
|
scopes.remove(s)
|
||||||
|
scopes.update(resolve_import_paths(set(s.follow())))
|
||||||
|
return scopes
|
||||||
|
|
||||||
pos = (line, column)
|
pos = (line, column)
|
||||||
f = modules.ModuleWithCursor(source_path, source=source, position=pos)
|
f = modules.ModuleWithCursor(source_path, source=source, position=pos)
|
||||||
goto_path = f.get_path_under_cursor()
|
goto_path = f.get_path_under_cursor()
|
||||||
@@ -253,11 +260,7 @@ def get_definition(source, line, column, source_path):
|
|||||||
else:
|
else:
|
||||||
scopes = set(_prepare_goto(pos, source_path, f, goto_path))
|
scopes = set(_prepare_goto(pos, source_path, f, goto_path))
|
||||||
|
|
||||||
for s in scopes.copy():
|
scopes = resolve_import_paths(scopes)
|
||||||
if isinstance(s, imports.ImportPath):
|
|
||||||
scopes.remove(s)
|
|
||||||
evaluate.statement_path = []
|
|
||||||
scopes.update(evaluate.goto([s]))
|
|
||||||
|
|
||||||
# add keywords
|
# add keywords
|
||||||
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
scopes |= keywords.get_keywords(string=goto_path, pos=pos)
|
||||||
|
|||||||
@@ -89,9 +89,8 @@ class ImportPath(object):
|
|||||||
for s, scope_names in evaluate.get_names_for_scope(scope,
|
for s, scope_names in evaluate.get_names_for_scope(scope,
|
||||||
include_builtin=False):
|
include_builtin=False):
|
||||||
for n in scope_names:
|
for n in scope_names:
|
||||||
if not isinstance(n.parent(), parsing.Import) \
|
if self.import_stmt.from_ns is None \
|
||||||
and (self.import_stmt.from_ns is None \
|
or self.is_partial_import:
|
||||||
or self.is_partial_import):
|
|
||||||
# from_ns must be defined to access module
|
# from_ns must be defined to access module
|
||||||
# values plus a partial import means that there
|
# values plus a partial import means that there
|
||||||
# is something after the import, which
|
# is something after the import, which
|
||||||
|
|||||||
Reference in New Issue
Block a user