Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created July 10, 2025 22:14
Show Gist options
  • Save mypy-play/b843af1de98a6c95b0baf2363220bc9b to your computer and use it in GitHub Desktop.
Save mypy-play/b843af1de98a6c95b0baf2363220bc9b to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import overload
class A[T]: ...
class B[T: (int, str)](A[T]):
@overload
def __new__(cls: type[B[int]]) -> B[int]: ...
@overload
def __new__(cls: type[B[str]]) -> B[str]: ...
def __new__(cls): raise NotImplementedError
def foo(x: A[str]) -> None:
if isinstance(x, B):
reveal_type(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment