1
0
forked from VimPlug/jedi

Merge StubName and CompiledNameWithStub

This commit is contained in:
Dave Halter
2018-11-30 23:36:30 +01:00
parent dd1e53b498
commit a07b062752
3 changed files with 11 additions and 31 deletions

View File

@@ -216,6 +216,7 @@ class AbstractUsedNamesFilter(AbstractFilter):
class ParserTreeFilter(AbstractUsedNamesFilter):
# TODO remove evaluator as an argument, it's not used.
def __init__(self, evaluator, context, node_context=None, until_position=None,
origin_scope=None):
"""

View File

@@ -543,6 +543,7 @@ def _remove_statements(evaluator, context, stmt, name):
def tree_name_to_contexts(evaluator, context, tree_name):
context_set = NO_CONTEXTS
module_node = context.get_root_context().tree_node
# First check for annotations, like: `foo: int = 3`
if module_node is not None:
names = module_node.get_used_names().get(tree_name.value, [])
for name in names:

View File

@@ -16,7 +16,7 @@ from jedi.evaluate.context.function import FunctionMixin
from jedi.evaluate.context.klass import ClassMixin
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
TypingModuleName
from jedi.evaluate.compiled.context import CompiledName, CompiledObject
from jedi.evaluate.compiled.context import CompiledObject
from jedi.evaluate.utils import to_list, safe_property
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -177,16 +177,21 @@ class TypeshedPlugin(BasePlugin):
return wrapper
class NameWithStubMixin(object):
class StubName(NameWrapper):
"""
This name is only here to mix stub names with non-stub names. The idea is
that the user can goto the actual name, but end up on the definition of the
stub when inferring types.
"""
def __init__(self, parent_context, non_stub_name, stub_name):
super(StubName, self).__init__(non_stub_name)
self.parent_context = parent_context
self._stub_name = stub_name
@memoize_method
@iterator_to_context_set
def infer(self):
actual_contexts = self._get_actual_contexts()
actual_contexts = self._wrapped_name.infer()
stub_contexts = self._stub_name.infer()
if not actual_contexts:
@@ -252,29 +257,6 @@ class StubOnlyName(TreeNameDefinition):
]
class StubName(NameWithStubMixin, NameWrapper):
def __init__(self, parent_context, non_stub_name, stub_name):
super(StubName, self).__init__(non_stub_name)
self.parent_context = parent_context
self._stub_name = stub_name
def _get_actual_contexts(self):
# This is intentionally a subclass of NameWithStubMixin.
return self._wrapped_name.infer()
class CompiledNameWithStub(NameWithStubMixin, NameWrapper):
# TODO do we actually need this class?
def __init__(self, compiled_name, stub_name):
super(CompiledNameWithStub, self).__init__(stub_name)
self._compiled_name = compiled_name
self._stub_name = stub_name
def _get_actual_contexts(self):
# This is intentionally a subclass of NameWithStubMixin.
return self._compiled_name.infer()
class StubOnlyFilter(ParserTreeFilter):
name_class = StubOnlyName
@@ -358,11 +340,7 @@ class StubFilter(AbstractFilter):
if isinstance(self._stub_filters[0].context, TypingModuleWrapper):
stub_name = TypingModuleName(stub_name)
if isinstance(name, CompiledName):
# TODO remove this?
result.append(CompiledNameWithStub(name, stub_name))
else:
result.append(StubName(self._parent_context, name, stub_name))
result.append(StubName(self._parent_context, name, stub_name))
return result
def __repr__(self):