Код: Выделить всё
from collections.abc import Callable
from typing import Generic, TypeVar
T = TypeVar("T")
U = TypeVar("U")
V = TypeVar("V")
class Pipeline(Generic[T, U]):
def pipe(self, _cb: Callable[[U], V]) -> "Pipeline[T, V]":
...
def int_to_str(x: int) -> str:
return str(x)
a = Pipeline()
a = a.pipe(int_to_str)
# the inferred type is Pipeline[Unknown, str]
# I would like it to be Pipeline[int, str]
Я пытался поиграть с @overload и т. д., но у меня ничего не получилось.
Подробнее здесь: https://stackoverflow.com/questions/774 ... thod-input