diff --git a/jedi/evaluate/context/typing.py b/jedi/evaluate/context/typing.py index 2892cf9b..12841627 100644 --- a/jedi/evaluate/context/typing.py +++ b/jedi/evaluate/context/typing.py @@ -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) diff --git a/test/completion/basic.py b/test/completion/basic.py index ae2e3128..0cb12e92 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -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: