Evaluate constraints instead of Any

This commit is contained in:
Dave Halter
2018-09-06 00:59:42 +02:00
parent 9cbf20aa48
commit 4730c71b16
2 changed files with 16 additions and 2 deletions

View File

@@ -400,6 +400,12 @@ class TypeVar(_BaseTypingContext):
debug.warning('Tried to infer a TypeVar without a given type')
return NO_CONTEXTS
@property
def constraints(self):
return ContextSet.from_sets(
lazy.infer() for lazy in self._constraints_lazy_contexts
)
def execute_annotation(self):
return self.get_classes().execute_annotation()
@@ -425,7 +431,15 @@ class BoundTypeVarName(AbstractNameDefinition):
self._context_set = context_set
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):
return '<%s %s -> %s>' % (self.__class__.__name__, self.var_name, self._context_set)

View File

@@ -300,7 +300,7 @@ with open('') as f:
#? ['closed']
f.closed
for line in f:
#? str()
#? str() bytes()
line
with open('') as f1, open('') as f2: