mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Better typevar class comparisons
This commit is contained in:
@@ -16,6 +16,7 @@ from jedi.evaluate.base_context import ContextualizedNode, NO_CONTEXTS, \
|
|||||||
ContextSet, TreeContext
|
ContextSet, TreeContext
|
||||||
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \
|
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \
|
||||||
LazyTreeContext
|
LazyTreeContext
|
||||||
|
from jedi.evaluate.context.typing import TypeVar
|
||||||
from jedi.evaluate.context import iterable
|
from jedi.evaluate.context import iterable
|
||||||
from jedi.evaluate.context import asynchronous
|
from jedi.evaluate.context import asynchronous
|
||||||
from jedi import parser_utils
|
from jedi import parser_utils
|
||||||
@@ -335,11 +336,21 @@ def signature_matches(function_context, arguments):
|
|||||||
function_context.parent_context,
|
function_context.parent_context,
|
||||||
param_node.annotation
|
param_node.annotation
|
||||||
)
|
)
|
||||||
return has_same_class(argument.infer().py__class__(), annotation_result)
|
return has_same_class(
|
||||||
|
argument.infer().py__class__(),
|
||||||
|
_type_vars_to_classes(annotation_result),
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _type_vars_to_classes(context_set):
|
||||||
|
return ContextSet.from_sets(
|
||||||
|
context.get_classes() if isinstance(context, TypeVar) else set([context])
|
||||||
|
for context in context_set
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def has_same_class(context_set1, context_set2):
|
def has_same_class(context_set1, context_set2):
|
||||||
for c1 in context_set1:
|
for c1 in context_set1:
|
||||||
for c2 in context_set2:
|
for c2 in context_set2:
|
||||||
|
|||||||
@@ -391,12 +391,19 @@ class TypeVar(_BaseTypingContext):
|
|||||||
def get_filters(self, *args, **kwargs):
|
def get_filters(self, *args, **kwargs):
|
||||||
return iter([])
|
return iter([])
|
||||||
|
|
||||||
def execute_annotation(self):
|
def get_classes(self):
|
||||||
if self._bound_lazy_context is not None:
|
if self._bound_lazy_context is not None:
|
||||||
return self._bound_lazy_context.infer().execute_annotation()
|
return self._bound_lazy_context.infer()
|
||||||
|
if self._constraints_lazy_contexts:
|
||||||
|
return ContextSet.from_sets(
|
||||||
|
l.infer() for l in self._constraints_lazy_contexts
|
||||||
|
)
|
||||||
debug.warning('Tried to infer a TypeVar without a given type')
|
debug.warning('Tried to infer a TypeVar without a given type')
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
|
def execute_annotation(self):
|
||||||
|
return self.get_classes().execute_annotation()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self.var_name)
|
return '<%s: %s>' % (self.__class__.__name__, self.var_name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user