mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Fix namespace autocompletion error
This commit is contained in:
committed by
Dave Halter
parent
3c909a9849
commit
fc14aad8f2
@@ -3,25 +3,19 @@ from itertools import chain
|
|||||||
|
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate.filters import DictFilter, AbstractNameDefinition
|
from jedi.evaluate.filters import DictFilter, AbstractNameDefinition, ContextNameMixin
|
||||||
from jedi.evaluate.base_context import TreeContext, ContextSet
|
from jedi.evaluate.base_context import TreeContext, ContextSet
|
||||||
|
|
||||||
|
|
||||||
class ImplicitNSName(AbstractNameDefinition):
|
class ImplicitNSName(ContextNameMixin, AbstractNameDefinition):
|
||||||
"""
|
"""
|
||||||
Accessing names for implicit namespace packages should infer to nothing.
|
Accessing names for implicit namespace packages should infer to nothing.
|
||||||
This object will prevent Jedi from raising exceptions
|
This object will prevent Jedi from raising exceptions
|
||||||
"""
|
"""
|
||||||
def __init__(self, implicit_ns_context, string_name):
|
def __init__(self, implicit_ns_context, string_name):
|
||||||
self.parent_context = implicit_ns_context
|
self._context = implicit_ns_context
|
||||||
self.string_name = string_name
|
self.string_name = string_name
|
||||||
|
|
||||||
def infer(self):
|
|
||||||
return ContextSet(self.parent_context)
|
|
||||||
|
|
||||||
def get_root_context(self):
|
|
||||||
return self.parent_context
|
|
||||||
|
|
||||||
|
|
||||||
class ImplicitNamespaceContext(TreeContext):
|
class ImplicitNamespaceContext(TreeContext):
|
||||||
"""
|
"""
|
||||||
@@ -56,9 +50,11 @@ class ImplicitNamespaceContext(TreeContext):
|
|||||||
"""
|
"""
|
||||||
return self._fullname
|
return self._fullname
|
||||||
|
|
||||||
@property
|
|
||||||
def py__path__(self):
|
def py__path__(self):
|
||||||
return lambda: [self.paths]
|
return [self.paths]
|
||||||
|
|
||||||
|
def py__name__(self):
|
||||||
|
return self._fullname
|
||||||
|
|
||||||
@evaluator_method_cache()
|
@evaluator_method_cache()
|
||||||
def _sub_modules_dict(self):
|
def _sub_modules_dict(self):
|
||||||
|
|||||||
@@ -93,3 +93,13 @@ def test_namespace_package_in_multiple_directories_goto_definition(Script):
|
|||||||
script = Script(sys_path=sys_path, source=CODE)
|
script = Script(sys_path=sys_path, source=CODE)
|
||||||
result = script.goto_definitions()
|
result = script.goto_definitions()
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_namespace_name_autocompletion_full_name(Script):
|
||||||
|
CODE = 'from pk'
|
||||||
|
sys_path = [join(dirname(__file__), d)
|
||||||
|
for d in ['implicit_namespace_package/ns1', 'implicit_namespace_package/ns2']]
|
||||||
|
|
||||||
|
script = Script(sys_path=sys_path, source=CODE)
|
||||||
|
compl = script.completions()
|
||||||
|
assert set(c.full_name for c in compl) == set(['pkg'])
|
||||||
|
|||||||
Reference in New Issue
Block a user