forked from VimPlug/jedi
Last few on_import fixes.
This commit is contained in:
@@ -144,14 +144,15 @@ class Script(object):
|
||||
# TODO this paragraph is necessary, but not sure it works.
|
||||
context = self._user_context.get_context()
|
||||
next(context) # skip the path
|
||||
if False and next(context) == 'from':
|
||||
if next(context) == 'from':
|
||||
# completion is just "import" if before stands from ..
|
||||
completions += ((k, bs) for k in keywords.keyword_names('import'))
|
||||
|
||||
module = self._parser.module()
|
||||
name = user_stmt.name_for_position(self._pos)
|
||||
if name is not None:
|
||||
imp = imports.ImportWrapper(self._evaluator, name)
|
||||
completions += [(n, module) for n in imp.completions()]
|
||||
completions += [(n, module) for n in imp.completion_names()]
|
||||
|
||||
if importer or isinstance(user_stmt, pr.Import):
|
||||
return completions
|
||||
|
||||
@@ -57,7 +57,7 @@ def importer_from_error_statement(evaluator, module, error_statement, pos):
|
||||
elif typ == 'import_from':
|
||||
for node in nodes:
|
||||
if isinstance(node, pt.Node) and node.type == 'dotted_name':
|
||||
names += check_dotted(node.children[::2])
|
||||
names += check_dotted(node.children)
|
||||
elif node in ('.', '...'):
|
||||
level += len(node.value)
|
||||
elif isinstance(node, pt.Name) and node.end_pos < pos:
|
||||
|
||||
@@ -47,7 +47,7 @@ class ImportWrapper(pr.Base):
|
||||
self.import_path = self._import.path_for_name(name)
|
||||
self.is_like_search = False # TODO REMOVE
|
||||
|
||||
def completions(self):
|
||||
def completion_names(self):
|
||||
# The import path needs to be reduced by one, because we're completing.
|
||||
import_path = self.import_path[:-1]
|
||||
module = self._import.get_parent_until()
|
||||
@@ -628,7 +628,6 @@ class _Importer(object):
|
||||
"""
|
||||
names = []
|
||||
if self.import_path:
|
||||
for scope in self.follow(evaluator):
|
||||
# flask
|
||||
if self.str_import_path == ('flask', 'ext'):
|
||||
# List Flask extensions like ``flask_foo``
|
||||
@@ -643,13 +642,15 @@ class _Importer(object):
|
||||
if os.path.isdir(flaskext):
|
||||
names += self._get_module_names([flaskext])
|
||||
|
||||
from jedi.evaluate import finder, representation as er
|
||||
for scope in self.follow(evaluator):
|
||||
# namespace packages
|
||||
if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'):
|
||||
pkg_path = os.path.dirname(scope.path)
|
||||
paths = self.namespace_packages(pkg_path, self.import_path)
|
||||
names += self._get_module_names([pkg_path] + paths)
|
||||
|
||||
if only_modules:
|
||||
if only_modules or not isinstance(scope, er.ModuleWrapper):
|
||||
# In the case of an import like `from x.` we don't need to
|
||||
# add all the variables.
|
||||
if ('os',) == self.str_import_path and not self.level:
|
||||
@@ -659,15 +660,6 @@ class _Importer(object):
|
||||
|
||||
continue
|
||||
|
||||
# TODO delete
|
||||
if False and not self.import_stmt.from_names or False and self.is_partial_import:
|
||||
# from_names must be defined to access module
|
||||
# values plus a partial import means that there
|
||||
# is something after the import, which
|
||||
# automatically implies that there must not be
|
||||
# any non-module scope.
|
||||
continue
|
||||
from jedi.evaluate import finder
|
||||
for s, scope_names in finder.get_names_of_scope(self._evaluator,
|
||||
scope, include_builtin=False):
|
||||
for n in scope_names:
|
||||
|
||||
@@ -61,10 +61,10 @@ import datetime.
|
||||
#? []
|
||||
import datetime.date
|
||||
|
||||
#? 17 ['import']
|
||||
from import_tree import pkg
|
||||
#? 18 ['import', 'pkg']
|
||||
from import_tree. import pkg
|
||||
#? 21 ['import']
|
||||
from import_tree.pkg import pkg
|
||||
#? 22 ['import', 'mod1']
|
||||
from import_tree.pkg. import mod1
|
||||
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2']
|
||||
from import_tree. import pkg
|
||||
|
||||
|
||||
Reference in New Issue
Block a user