1
0
forked from VimPlug/jedi

Import issues again.

This commit is contained in:
Dave Halter
2014-09-24 21:59:08 +02:00
parent c43afae24a
commit 9ecf3774a0
3 changed files with 14 additions and 11 deletions

View File

@@ -297,7 +297,7 @@ class FakeStatement(pr.ExprStmt):
class FakeImport(pr.Import): class FakeImport(pr.Import):
def __init__(self, name, parent, level=0): def __init__(self, name, parent, level=0):
p = 0, 0 p = 0, 0
super(FakeImport, self).__init__(FakeSubModule, p, p, name, super(FakeImport, self).__init__(FakeSubModule, p, p, [name],
relative_count=level) relative_count=level)
self.parent = parent self.parent = parent

View File

@@ -110,6 +110,7 @@ class ImportWrapper(pr.Base):
m = _load_module(rel_path) m = _load_module(rel_path)
names += m.get_defined_names() names += m.get_defined_names()
else: else:
# flask
if self.import_path == ('flask', 'ext'): if self.import_path == ('flask', 'ext'):
# List Flask extensions like ``flask_foo`` # List Flask extensions like ``flask_foo``
for mod in self._get_module_names(): for mod in self._get_module_names():
@@ -122,6 +123,8 @@ class ImportWrapper(pr.Base):
flaskext = os.path.join(dir, 'flaskext') flaskext = os.path.join(dir, 'flaskext')
if os.path.isdir(flaskext): if os.path.isdir(flaskext):
names += self._get_module_names([flaskext]) names += self._get_module_names([flaskext])
# namespace packages
if on_import_stmt and isinstance(scope, pr.Module) \ if on_import_stmt and isinstance(scope, pr.Module) \
and scope.path.endswith('__init__.py'): and scope.path.endswith('__init__.py'):
pkg_path = os.path.dirname(scope.path) pkg_path = os.path.dirname(scope.path)
@@ -136,18 +139,18 @@ class ImportWrapper(pr.Base):
# ``sys.modules`` modification. # ``sys.modules`` modification.
names.append(self._generate_name('path')) names.append(self._generate_name('path'))
continue continue
from jedi.evaluate import finder
for s, scope_names in finder.get_names_of_scope(self._evaluator, if not self.import_stmt.from_names or self.is_partial_import:
scope, include_builtin=False):
for n in scope_names:
if self.import_stmt.from_names is None \
or self.is_partial_import:
# from_names must be defined to access module # from_names 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
# automatically implies that there must not be # automatically implies that there must not be
# any non-module scope. # any non-module scope.
continue 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:
names.append(n) names.append(n)
return names return names

View File

@@ -499,8 +499,8 @@ class Parser(object):
if star: if star:
names = [] names = []
e = (alias or names and names[-1] or self._gen.previous).end_pos e = (alias or names and names[-1] or self._gen.previous).end_pos
end_pos = self._gen.previous.end_pos if count + 1 == len(names) else e #end_pos = self._gen.previous.end_pos if count + 1 == len(names) else e
i = pr.Import(self.module, first_pos, end_pos, names, i = pr.Import(self.module, first_pos, e, names,
alias, from_names, star, relative_count, alias, from_names, star, relative_count,
defunct=defunct or defunct2) defunct=defunct or defunct2)
self._check_user_stmt(i) self._check_user_stmt(i)