forked from VimPlug/jedi
Differentiate between namespace and module as a type
Also fixed a bug related to implicit namespace contexts, fixes #1033.
This commit is contained in:
@@ -153,13 +153,13 @@ class BaseDefinition(object):
|
||||
"""The path to a module/class/function definition."""
|
||||
def to_reverse():
|
||||
name = self._name
|
||||
if name.api_type == 'module':
|
||||
if name.api_type in ('module', 'namespace'):
|
||||
try:
|
||||
name = list(name.infer())[0].name
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
if name.api_type == 'module':
|
||||
if name.api_type in ('module', 'namespace'):
|
||||
module_contexts = name.infer()
|
||||
if module_contexts:
|
||||
module_context, = module_contexts
|
||||
@@ -521,7 +521,7 @@ class Definition(BaseDefinition):
|
||||
"""
|
||||
typ = self.type
|
||||
tree_name = self._name.tree_name
|
||||
if typ in ('function', 'class', 'module', 'instance') or tree_name is None:
|
||||
if typ in ('function', 'class', 'module', 'instance', 'namespace') or tree_name is None:
|
||||
if typ == 'function':
|
||||
# For the description we want a short and a pythonic way.
|
||||
typ = 'def'
|
||||
|
||||
@@ -13,21 +13,21 @@ class ImplicitNSName(AbstractNameDefinition):
|
||||
This object will prevent Jedi from raising exceptions
|
||||
"""
|
||||
def __init__(self, implicit_ns_context, string_name):
|
||||
self.implicit_ns_context = implicit_ns_context
|
||||
self.parent_context = implicit_ns_context
|
||||
self.string_name = string_name
|
||||
|
||||
def infer(self):
|
||||
return NO_CONTEXTS
|
||||
|
||||
def get_root_context(self):
|
||||
return self.implicit_ns_context
|
||||
return self.parent_context
|
||||
|
||||
|
||||
class ImplicitNamespaceContext(TreeContext):
|
||||
"""
|
||||
Provides support for implicit namespace packages
|
||||
"""
|
||||
api_type = u'module'
|
||||
api_type = u'namespace'
|
||||
parent_context = None
|
||||
|
||||
def __init__(self, evaluator, fullname, paths):
|
||||
|
||||
@@ -419,7 +419,7 @@ class Importer(object):
|
||||
|
||||
for context in self.follow():
|
||||
# Non-modules are not completable.
|
||||
if context.api_type != 'module': # not a module
|
||||
if context.api_type not in ('namespace', 'module'): # not a module
|
||||
continue
|
||||
# namespace packages
|
||||
if isinstance(context, ModuleContext) and context.py__file__().endswith('__init__.py'):
|
||||
|
||||
@@ -51,12 +51,15 @@ def test_implicit_nested_namespace_package(Script, environment):
|
||||
if environment.version_info < (3, 4):
|
||||
pytest.skip()
|
||||
|
||||
CODE = 'from implicit_nested_namespaces.namespace.pkg.module import CONST'
|
||||
code = 'from implicit_nested_namespaces.namespace.pkg.module import CONST'
|
||||
|
||||
sys_path = [dirname(__file__)]
|
||||
|
||||
script = Script(sys_path=sys_path, source=CODE, line=1, column=61)
|
||||
script = Script(sys_path=sys_path, source=code, line=1, column=61)
|
||||
|
||||
result = script.goto_definitions()
|
||||
|
||||
assert len(result) == 1
|
||||
|
||||
implicit_pkg, = Script(code, column=10, sys_path=sys_path).goto_definitions()
|
||||
assert implicit_pkg.type == 'namespace'
|
||||
|
||||
Reference in New Issue
Block a user