Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created March 8, 2025 18:50
Show Gist options
  • Save mypy-play/eb0368ff186c5e35e136bbc3eba0d98c to your computer and use it in GitHub Desktop.
Save mypy-play/eb0368ff186c5e35e136bbc3eba0d98c to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from collections.abc import Callable
from enum import Enum
from typing import Generic, Protocol, TypeVar, Type, overload
T = TypeVar("T", covariant=True)
class A(Generic[T]):
pass
class B:
pass
AT1 = TypeVar("AT1", bound=A)
AT2 = TypeVar("AT2", bound=A)
def my_decorator(func: Callable[[AT1], AT2]) -> Callable[[AT1 | B], AT2]: ...
@my_decorator
def f(a: A[float]) -> A[int]: ...
reveal_type(my_decorator)
reveal_type(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment