forked from VimPlug/jedi
Merge StubName and CompiledNameWithStub
This commit is contained in:
@@ -216,6 +216,7 @@ class AbstractUsedNamesFilter(AbstractFilter):
|
|||||||
|
|
||||||
|
|
||||||
class ParserTreeFilter(AbstractUsedNamesFilter):
|
class ParserTreeFilter(AbstractUsedNamesFilter):
|
||||||
|
# TODO remove evaluator as an argument, it's not used.
|
||||||
def __init__(self, evaluator, context, node_context=None, until_position=None,
|
def __init__(self, evaluator, context, node_context=None, until_position=None,
|
||||||
origin_scope=None):
|
origin_scope=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ def _remove_statements(evaluator, context, stmt, name):
|
|||||||
def tree_name_to_contexts(evaluator, context, tree_name):
|
def tree_name_to_contexts(evaluator, context, tree_name):
|
||||||
context_set = NO_CONTEXTS
|
context_set = NO_CONTEXTS
|
||||||
module_node = context.get_root_context().tree_node
|
module_node = context.get_root_context().tree_node
|
||||||
|
# First check for annotations, like: `foo: int = 3`
|
||||||
if module_node is not None:
|
if module_node is not None:
|
||||||
names = module_node.get_used_names().get(tree_name.value, [])
|
names = module_node.get_used_names().get(tree_name.value, [])
|
||||||
for name in names:
|
for name in names:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from jedi.evaluate.context.function import FunctionMixin
|
|||||||
from jedi.evaluate.context.klass import ClassMixin
|
from jedi.evaluate.context.klass import ClassMixin
|
||||||
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
||||||
TypingModuleName
|
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
|
from jedi.evaluate.utils import to_list, safe_property
|
||||||
|
|
||||||
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
@@ -177,16 +177,21 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class NameWithStubMixin(object):
|
class StubName(NameWrapper):
|
||||||
"""
|
"""
|
||||||
This name is only here to mix stub names with non-stub names. The idea is
|
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
|
that the user can goto the actual name, but end up on the definition of the
|
||||||
stub when inferring types.
|
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
|
@memoize_method
|
||||||
@iterator_to_context_set
|
@iterator_to_context_set
|
||||||
def infer(self):
|
def infer(self):
|
||||||
actual_contexts = self._get_actual_contexts()
|
actual_contexts = self._wrapped_name.infer()
|
||||||
stub_contexts = self._stub_name.infer()
|
stub_contexts = self._stub_name.infer()
|
||||||
|
|
||||||
if not actual_contexts:
|
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):
|
class StubOnlyFilter(ParserTreeFilter):
|
||||||
name_class = StubOnlyName
|
name_class = StubOnlyName
|
||||||
|
|
||||||
@@ -358,10 +340,6 @@ class StubFilter(AbstractFilter):
|
|||||||
if isinstance(self._stub_filters[0].context, TypingModuleWrapper):
|
if isinstance(self._stub_filters[0].context, TypingModuleWrapper):
|
||||||
stub_name = TypingModuleName(stub_name)
|
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
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user