1
0
forked from VimPlug/jedi

A stab at davidhalter/jedi#361 (Flask extension imports)

Both new-style and old-style extensions work, but only when imported
with a 'from'.  There are two skipped tests of the full dotted name
imports.

Also, our fixture has a normal flaskext package, whereas in practice
the flaskext module is injected from a pth file and does not have
__init__.py, we need to figure out to handle that.
This commit is contained in:
Albertas Agejevas
2014-07-27 12:40:35 +02:00
parent e2cdbf61de
commit 13c1f79d5c
7 changed files with 61 additions and 0 deletions
+19
View File
@@ -343,6 +343,25 @@ class _Importer(object):
@memoize_default(NO_DEFAULT)
def follow_file_system(self):
# Handle "magic" Flask extension imports:
# ``flask.ext.foo`` is really ``flask_foo`` or ``flaskext.foo``.
if [part._string for part in self.import_path[:2]] == ['flask', 'ext']:
orig_path = tuple(self.import_path)
part = orig_path[2]
pos = (part._line, part._column)
try:
self.import_path = (
pr.NamePart('flask_' + part._string, part.parent, pos),
) + orig_path[3:]
return self._real_follow_file_system()
except ModuleNotFound as e:
self.import_path = (
pr.NamePart('flaskext', part.parent, pos),
) + orig_path[2:]
return self._real_follow_file_system()
return self._real_follow_file_system()
def _real_follow_file_system(self):
if self.file_path:
sys_path_mod = list(self.sys_path_with_modifications())
if not self.module.has_explicit_absolute_import: