mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
fix problem with variables in from clauses, #268
This commit is contained in:
@@ -536,8 +536,13 @@ class Script(object):
|
|||||||
cur_name_part = name_part
|
cur_name_part = name_part
|
||||||
kill_count += 1
|
kill_count += 1
|
||||||
|
|
||||||
|
|
||||||
|
context = self._module.get_context()
|
||||||
|
just_from = next(context) == 'from'
|
||||||
|
|
||||||
i = imports.ImportPath(user_stmt, is_like_search,
|
i = imports.ImportPath(user_stmt, is_like_search,
|
||||||
kill_count=kill_count, direct_resolve=True)
|
kill_count=kill_count, direct_resolve=True,
|
||||||
|
is_just_from=just_from)
|
||||||
return i, cur_name_part
|
return i, cur_name_part
|
||||||
|
|
||||||
def _get_completion_parts(self):
|
def _get_completion_parts(self):
|
||||||
|
|||||||
@@ -56,10 +56,12 @@ class ImportPath(pr.Base):
|
|||||||
GlobalNamespace = _GlobalNamespace()
|
GlobalNamespace = _GlobalNamespace()
|
||||||
|
|
||||||
def __init__(self, import_stmt, is_like_search=False, kill_count=0,
|
def __init__(self, import_stmt, is_like_search=False, kill_count=0,
|
||||||
direct_resolve=False):
|
direct_resolve=False, is_just_from=False):
|
||||||
self.import_stmt = import_stmt
|
self.import_stmt = import_stmt
|
||||||
self.is_like_search = is_like_search
|
self.is_like_search = is_like_search
|
||||||
self.direct_resolve = direct_resolve
|
self.direct_resolve = direct_resolve
|
||||||
|
self.is_just_from = is_just_from
|
||||||
|
|
||||||
self.is_partial_import = bool(max(0, kill_count))
|
self.is_partial_import = bool(max(0, kill_count))
|
||||||
path = import_stmt.get_parent_until().path
|
path = import_stmt.get_parent_until().path
|
||||||
self.file_path = os.path.dirname(path) if path is not None else None
|
self.file_path = os.path.dirname(path) if path is not None else None
|
||||||
@@ -131,6 +133,16 @@ class ImportPath(pr.Base):
|
|||||||
pkg_path = os.path.dirname(scope.path)
|
pkg_path = os.path.dirname(scope.path)
|
||||||
paths = self._namespace_packages(pkg_path, self.import_path)
|
paths = self._namespace_packages(pkg_path, self.import_path)
|
||||||
names += self._get_module_names([pkg_path] + paths)
|
names += self._get_module_names([pkg_path] + paths)
|
||||||
|
if self.is_just_from:
|
||||||
|
# In the case of an import like `from x.` we don't need to
|
||||||
|
# add all the variables.
|
||||||
|
if ['os'] == self.import_path and not self._is_relative_import():
|
||||||
|
# os.path is a hardcoded exception, because it's a
|
||||||
|
# ``sys.modules`` modification.
|
||||||
|
p = (0, 0)
|
||||||
|
names.append(pr.Name(self.GlobalNamespace, [('path', p)],
|
||||||
|
p, p, self.import_stmt))
|
||||||
|
continue
|
||||||
for s, scope_names in evaluate.get_names_of_scope(scope,
|
for s, scope_names in evaluate.get_names_of_scope(scope,
|
||||||
include_builtin=False):
|
include_builtin=False):
|
||||||
for n in scope_names:
|
for n in scope_names:
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ def scope_nested2():
|
|||||||
#? []
|
#? []
|
||||||
import_tree.rename1
|
import_tree.rename1
|
||||||
|
|
||||||
|
def from_names():
|
||||||
|
#? ['mod1']
|
||||||
|
from import_tree.pkg.
|
||||||
|
#? ['path']
|
||||||
|
from os.
|
||||||
|
|
||||||
def builtin_test():
|
def builtin_test():
|
||||||
#? ['math']
|
#? ['math']
|
||||||
import math
|
import math
|
||||||
|
|||||||
Reference in New Issue
Block a user