Created
December 5, 2025 10:44
-
-
Save mypy-play/22f7d5fb1f2f5f90634162a9c5d123dd to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Final | |
| def foo(foo: Foo[int | str]) -> None: | |
| pass | |
| def bar(bar: Bar[int | str]) -> None: | |
| pass | |
| # Generic is not covariant because it used in mutable state | |
| class Foo[T: int | str]: | |
| def __init__(self, value: T): | |
| self.value = value # mutable variable | |
| def mmethod(self) -> None: | |
| foo(self) | |
| # Generic is covariant because it not used in mutable state | |
| class Bar[T: int | str]: | |
| def __init__(self, value: T): | |
| self.value: Final = value # read-only variable | |
| def method(self) -> None: | |
| bar(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment