Open betodealmeida opened 2 years ago
Is it possible to infer the return type based on the input, for generic functions?
Eg, with this classic example:
from typing import TypeVar, Sequence T = TypeVar('T') # Declare type variable def first(seq: Sequence[T]) -> T: # Generic function return seq[0]
If I know that seq has type Sequence[int], how can I infer that first would return int in that case?
seq
Sequence[int]
first
int
Is it possible to infer the return type based on the input, for generic functions?
Eg, with this classic example:
If I know that
seq
has typeSequence[int]
, how can I infer thatfirst
would returnint
in that case?