forked from VimPlug/jedi
Import names are now always strings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from parso.python.tree import Name
|
||||
|
||||
from jedi.plugins.base import BasePlugin
|
||||
from jedi.evaluate.imports import JediImportError
|
||||
|
||||
|
||||
class FlaskPlugin(BasePlugin):
|
||||
@@ -9,21 +10,20 @@ class FlaskPlugin(BasePlugin):
|
||||
Handle "magic" Flask extension imports:
|
||||
``flask.ext.foo`` is really ``flask_foo`` or ``flaskext.foo``.
|
||||
"""
|
||||
def wrapper(evaluator, import_path, *args, **kwargs):
|
||||
import_parts = [
|
||||
i.value if isinstance(i, Name) else i
|
||||
for i in import_path
|
||||
]
|
||||
|
||||
if len(import_path) > 2 and import_parts[:2] == ['flask', 'ext']:
|
||||
def wrapper(evaluator, import_names, *args, **kwargs):
|
||||
if len(import_names) > 2 and import_names[:2] == ('flask', 'ext'):
|
||||
# New style.
|
||||
ipath = ('flask_' + str(import_parts[2]),) + import_path[3:]
|
||||
modules = callback(evaluator, ipath, *args, **kwargs)
|
||||
if modules:
|
||||
return modules
|
||||
else:
|
||||
ipath = ('flask_' + str(import_names[2]),) + import_names[3:]
|
||||
try:
|
||||
return callback(evaluator, ipath, *args, **kwargs)
|
||||
except JediImportError:
|
||||
# Old style
|
||||
return callback(evaluator, ('flaskext',) + import_path[2:], *args, **kwargs)
|
||||
return callback(evaluator, import_path, *args, **kwargs)
|
||||
return callback(
|
||||
evaluator,
|
||||
('flaskext',) + import_names[2:],
|
||||
*args,
|
||||
**kwargs
|
||||
)
|
||||
return callback(evaluator, import_names, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user