We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
from typing import TypeVar, Generic T_in = TypeVar("T_in", contravariant=True) T_out = TypeVar("T_out", covariant=True) class AOut(Generic[T_out]): ... class AIn(Generic[T_in]): ... class BOut(Generic[T_out]): def f(self, a_out: AOut[T_out]) -> None: ... # no error class BIn(Generic[T_in]): def f(self, a_out: AIn[T_in]) -> None: ... # no error
from typing import TypeVar, Generic, Callable T_in = TypeVar("T_in", contravariant=True) T_out = TypeVar("T_out", covariant=True) class AOut(Generic[T_out]): T: T_out def f(self, fn: Callable[[], T_out]) -> None: self.t = fn() def dump(self) -> T_out: return self.t class AIn(Generic[T_in]): t: T_in def load(self, t: T_in) -> None: self.t = t def f(self, fn: Callable[[T_in], object]) -> None: fn(self.t) o1: AOut[int] o: AOut[object] = o1 o.f(lambda: "") o1.dump() + 1 # runtime error i1: AIn[object] i: AIn[int] = i1 i1.load("") i.f(lambda x: x + 1) # runtime error
related: #734, #8191
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Mypy in real life
related: #734, #8191
The text was updated successfully, but these errors were encountered: