mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 03:25:55 +08:00
More on #361: enumerate new-style flask extensions.
This commit is contained in:
@@ -109,6 +109,13 @@ class ImportWrapper(pr.Base):
|
||||
m = _load_module(rel_path)
|
||||
names += m.get_defined_names()
|
||||
else:
|
||||
if self.import_path == ('flask', 'ext'):
|
||||
# List Flask extensions in ``flask_foo``
|
||||
for mod in self._get_module_names():
|
||||
modname = str(mod)
|
||||
if modname.startswith('flask_'):
|
||||
extname = modname[len('flask_'):]
|
||||
names.append(self._generate_name(extname))
|
||||
if on_import_stmt and isinstance(scope, pr.Module) \
|
||||
and scope.path.endswith('__init__.py'):
|
||||
pkg_path = os.path.dirname(scope.path)
|
||||
@@ -325,7 +332,7 @@ class _Importer(object):
|
||||
# `from gunicorn import something`. But gunicorn is not in the
|
||||
# sys.path. Therefore look if gunicorn is a parent directory, #56.
|
||||
in_path = []
|
||||
if self.import_path:
|
||||
if self.import_path and self.file_path is not None:
|
||||
parts = self.file_path.split(os.path.sep)
|
||||
for i, p in enumerate(parts):
|
||||
if p == unicode(self.import_path[0]):
|
||||
|
||||
@@ -43,6 +43,8 @@ def teardown_function(function):
|
||||
("from flask.ext import bar; bar.", "Bar"), # flaskext/bar.py
|
||||
("from flask.ext import baz; baz.", "Baz"), # flask_baz/__init__.py
|
||||
("from flask.ext import moo; moo.", "Moo"), # flaskext/moo/__init__.py
|
||||
("from flask.ext.", "foo"),
|
||||
("from flask.ext.", "baz"),
|
||||
pytest.mark.xfail(("import flask.ext.foo; flask.ext.foo.", "Foo")),
|
||||
pytest.mark.xfail(("import flask.ext.bar; flask.ext.bar.", "Foo")),
|
||||
pytest.mark.xfail(("import flask.ext.baz; flask.ext.baz.", "Foo")),
|
||||
@@ -53,6 +55,3 @@ def test_flask_ext(script, name):
|
||||
"""
|
||||
assert name in [c.name for c in jedi.Script(script).completions()]
|
||||
|
||||
|
||||
def test_flask_regression():
|
||||
jedi.Script("from flask.ext.").completions()
|
||||
|
||||
Reference in New Issue
Block a user