mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Evaluate constraints instead of Any
This commit is contained in:
@@ -400,6 +400,12 @@ class TypeVar(_BaseTypingContext):
|
|||||||
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
|
||||||
|
|
||||||
|
@property
|
||||||
|
def constraints(self):
|
||||||
|
return ContextSet.from_sets(
|
||||||
|
lazy.infer() for lazy in self._constraints_lazy_contexts
|
||||||
|
)
|
||||||
|
|
||||||
def execute_annotation(self):
|
def execute_annotation(self):
|
||||||
return self.get_classes().execute_annotation()
|
return self.get_classes().execute_annotation()
|
||||||
|
|
||||||
@@ -425,7 +431,15 @@ class BoundTypeVarName(AbstractNameDefinition):
|
|||||||
self._context_set = context_set
|
self._context_set = context_set
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
return self._context_set
|
def iter_():
|
||||||
|
for context in self._context_set:
|
||||||
|
# Replace any with the constraints if they are there.
|
||||||
|
if isinstance(context, Any):
|
||||||
|
for constraint in self._type_var.constraints:
|
||||||
|
yield constraint
|
||||||
|
else:
|
||||||
|
yield context
|
||||||
|
return ContextSet.from_iterable(iter_())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s %s -> %s>' % (self.__class__.__name__, self.var_name, self._context_set)
|
return '<%s %s -> %s>' % (self.__class__.__name__, self.var_name, self._context_set)
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ with open('') as f:
|
|||||||
#? ['closed']
|
#? ['closed']
|
||||||
f.closed
|
f.closed
|
||||||
for line in f:
|
for line in f:
|
||||||
#? str()
|
#? str() bytes()
|
||||||
line
|
line
|
||||||
|
|
||||||
with open('') as f1, open('') as f2:
|
with open('') as f1, open('') as f2:
|
||||||
|
|||||||
Reference in New Issue
Block a user