mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Implement StubParserTreeFilter.values
This commit is contained in:
@@ -204,7 +204,6 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
def in_builtin_module(self):
|
def in_builtin_module(self):
|
||||||
"""Whether this is a builtin module."""
|
"""Whether this is a builtin module."""
|
||||||
print(self._module)
|
|
||||||
if isinstance(self._module, StubOnlyModuleContext):
|
if isinstance(self._module, StubOnlyModuleContext):
|
||||||
return any(isinstance(context, compiled.CompiledObject)
|
return any(isinstance(context, compiled.CompiledObject)
|
||||||
for context in self._module.non_stub_context_set)
|
for context in self._module.non_stub_context_set)
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ from jedi.parser_utils import get_call_signature_for_any
|
|||||||
from jedi.evaluate.base_context import ContextSet, iterator_to_context_set, \
|
from jedi.evaluate.base_context import ContextSet, iterator_to_context_set, \
|
||||||
ContextWrapper
|
ContextWrapper
|
||||||
from jedi.evaluate.filters import AbstractTreeName, ParserTreeFilter, \
|
from jedi.evaluate.filters import AbstractTreeName, ParserTreeFilter, \
|
||||||
TreeNameDefinition, NameWrapper
|
TreeNameDefinition, NameWrapper, MergedFilter
|
||||||
from jedi.evaluate.context import ModuleContext, FunctionContext, \
|
from jedi.evaluate.context import ModuleContext, FunctionContext, \
|
||||||
ClassContext, BoundMethod
|
ClassContext
|
||||||
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
||||||
TypingModuleName
|
TypingModuleName
|
||||||
from jedi.evaluate.compiled import CompiledObject
|
from jedi.evaluate.compiled import CompiledObject
|
||||||
@@ -251,8 +251,24 @@ class StubParserTreeFilter(ParserTreeFilter):
|
|||||||
|
|
||||||
return self._convert_names(self._filter(names))
|
return self._convert_names(self._filter(names))
|
||||||
|
|
||||||
# TODO maybe implement values, because currently the names that don't exist
|
def values(self):
|
||||||
# in the stub file are not part of values.
|
used_stub_names = set()
|
||||||
|
result_names = []
|
||||||
|
for key_name, names in self._used_names.items():
|
||||||
|
result_names += self._convert_names(self._filter(names))
|
||||||
|
used_stub_names.add(key_name)
|
||||||
|
|
||||||
|
non_stub_filters = []
|
||||||
|
for f in self._non_stub_filters:
|
||||||
|
if isinstance(f, MergedFilter):
|
||||||
|
non_stub_filters += f._filters
|
||||||
|
else:
|
||||||
|
non_stub_filters.append(f)
|
||||||
|
for non_stub_filter in non_stub_filters:
|
||||||
|
for key_name in non_stub_filter._used_names:
|
||||||
|
if key_name not in used_stub_names:
|
||||||
|
result_names += non_stub_filter.get(key_name)
|
||||||
|
return result_names
|
||||||
|
|
||||||
def _check_flows(self, names):
|
def _check_flows(self, names):
|
||||||
return names
|
return names
|
||||||
@@ -361,25 +377,28 @@ class StubOnlyModuleContext(ModuleContext):
|
|||||||
|
|
||||||
def _get_first_non_stub_filters(self):
|
def _get_first_non_stub_filters(self):
|
||||||
for context in self.non_stub_context_set:
|
for context in self.non_stub_context_set:
|
||||||
yield next(context.get_filters(search_global=False))
|
if not isinstance(context, CompiledObject):
|
||||||
|
yield next(context.get_filters(search_global=False))
|
||||||
|
|
||||||
def get_filters(self, search_global, until_position=None,
|
def get_filters(self, search_global, until_position=None,
|
||||||
origin_scope=None, **kwargs):
|
origin_scope=None, **kwargs):
|
||||||
filters = super(StubOnlyModuleContext, self).get_filters(
|
filters = super(StubOnlyModuleContext, self).get_filters(
|
||||||
search_global, until_position, origin_scope, **kwargs
|
search_global, until_position, origin_scope, **kwargs
|
||||||
)
|
)
|
||||||
next(filters) # Ignore the first filter and replace it with our own
|
first_non_stub_filters = list(self._get_first_non_stub_filters())
|
||||||
|
|
||||||
# Here we remap the names from stubs to the actual module. This is
|
if first_non_stub_filters:
|
||||||
# important if type inferences is needed in that module.
|
next(filters) # Ignore the first filter and replace it with our own
|
||||||
yield StubParserTreeFilter(
|
# Here we remap the names from stubs to the actual module. This is
|
||||||
list(self._get_first_non_stub_filters()),
|
# important if type inferences is needed in that module.
|
||||||
self.evaluator,
|
yield StubParserTreeFilter(
|
||||||
context=self,
|
list(self._get_first_non_stub_filters()),
|
||||||
until_position=until_position,
|
self.evaluator,
|
||||||
origin_scope=origin_scope,
|
context=self,
|
||||||
search_global=search_global,
|
until_position=until_position,
|
||||||
)
|
origin_scope=origin_scope,
|
||||||
|
search_global=search_global,
|
||||||
|
)
|
||||||
for f in filters:
|
for f in filters:
|
||||||
yield f
|
yield f
|
||||||
|
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ def test_class_call_signature(Script):
|
|||||||
|
|
||||||
def test_position_none_if_builtin(Script):
|
def test_position_none_if_builtin(Script):
|
||||||
gotos = Script('import sys; sys.path').goto_assignments()
|
gotos = Script('import sys; sys.path').goto_assignments()
|
||||||
assert gotos[0].line is None
|
assert gotos[0].in_builtin_module()
|
||||||
assert gotos[0].column is None
|
assert gotos[0].line is not None
|
||||||
|
assert gotos[0].column is not None
|
||||||
|
|
||||||
|
|
||||||
def test_completion_docstring(Script, jedi_path):
|
def test_completion_docstring(Script, jedi_path):
|
||||||
|
|||||||
Reference in New Issue
Block a user