From 9ecf3774a00dd5a4376297834e8ccfa0d2d1db2f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 24 Sep 2014 21:59:08 +0200 Subject: [PATCH] Import issues again. --- jedi/evaluate/helpers.py | 2 +- jedi/evaluate/imports.py | 19 +++++++++++-------- jedi/parser/__init__.py | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index 2ad756e0..57f70632 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -297,7 +297,7 @@ class FakeStatement(pr.ExprStmt): class FakeImport(pr.Import): def __init__(self, name, parent, level=0): p = 0, 0 - super(FakeImport, self).__init__(FakeSubModule, p, p, name, + super(FakeImport, self).__init__(FakeSubModule, p, p, [name], relative_count=level) self.parent = parent diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index a2cc56b9..c508f637 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -110,6 +110,7 @@ class ImportWrapper(pr.Base): m = _load_module(rel_path) names += m.get_defined_names() else: + # flask if self.import_path == ('flask', 'ext'): # List Flask extensions like ``flask_foo`` for mod in self._get_module_names(): @@ -122,6 +123,8 @@ class ImportWrapper(pr.Base): flaskext = os.path.join(dir, 'flaskext') if os.path.isdir(flaskext): names += self._get_module_names([flaskext]) + + # namespace packages if on_import_stmt and isinstance(scope, pr.Module) \ and scope.path.endswith('__init__.py'): pkg_path = os.path.dirname(scope.path) @@ -136,18 +139,18 @@ class ImportWrapper(pr.Base): # ``sys.modules`` modification. names.append(self._generate_name('path')) continue + + if not self.import_stmt.from_names or 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: - if self.import_stmt.from_names is None \ - or 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 names.append(n) return names diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 290225f1..9a277374 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -499,8 +499,8 @@ class Parser(object): if star: names = [] 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 - i = pr.Import(self.module, first_pos, end_pos, names, + #end_pos = self._gen.previous.end_pos if count + 1 == len(names) else e + i = pr.Import(self.module, first_pos, e, names, alias, from_names, star, relative_count, defunct=defunct or defunct2) self._check_user_stmt(i)