Having
# python3.9
TypeA = tuple[int, float, int, str]
TypeB = tuple[int, str, set]
T = TypeVar("T", TypeA, TypeB)
def f(x: int) -> int:
return x * x
def yielding_function(payload: Iterable[T]) -> Iterator[T]:
for x0, *other in payload:
yield f(x0), *other
causes PyLance type error
Expression of type "tuple[int, *tuple[float* | int* | str* | set[Unknown]*, ...]]" cannot be assigned to yield type "T@yielding_function"
Type "tuple[int, *tuple[float* | int* | str* | set[Unknown]*, ...]]" cannot be assigned to type "T@yielding_function"
What is the correct type hint for yielding_function
? Or what is robust way of defining thereof? I wish that input and output would have the same type, so using unions is not possible here.