Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created November 16, 2025 00:57
Shared via mypy Playground
from dataclasses import dataclass
from typing import TYPE_CHECKING, TypeVar, dataclass_transform, Protocol
from functools import partial
if TYPE_CHECKING:
T = TypeVar('T')
@dataclass_transform(frozen_default = True)
def frozen(cls: type[T]) -> type[T]:
...
@mypy-play
mypy-play / main.py
Created November 15, 2025 19:49
Shared via mypy Playground
from typing import *
T = TypeVar("T", bound=int | float)
class Adder(Protocol[T]):
def add(self, x: T, y: T) -> T:
...
class IntAdder():
@mypy-play
mypy-play / main.py
Created November 15, 2025 08:42
Shared via mypy Playground
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
def main(foo: Thing) -> None:
print(obj)
@mypy-play
mypy-play / main.py
Created November 15, 2025 08:42
Shared via mypy Playground
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
def main(foo: Thing) -> None:
print(obj)
@mypy-play
mypy-play / main.py
Created November 15, 2025 08:42
Shared via mypy Playground
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
def main(foo: Thing) -> None:
print(obj)
@mypy-play
mypy-play / main.py
Created November 15, 2025 08:39
Shared via mypy Playground
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
async def main(foo: Thing) -> None:
print(obj)
@mypy-play
mypy-play / main.py
Created November 15, 2025 08:36
Shared via mypy Playground
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
async def main(foo: Thing) -> None:
print(obj)
@mypy-play
mypy-play / main.py
Created November 14, 2025 10:02
Shared via mypy Playground
from typing import NotRequired, TypedDict
class Foo(TypedDict):
key1: NotRequired[str]
key2: NotRequired[int]
foo = Foo()
for key in "key1", "key2":
@mypy-play
mypy-play / main.py
Created November 14, 2025 07:32
Shared via mypy Playground
import enum
import typing
class Op(enum.Enum):
A = "a"
B = "b"
def run(op: Op):
if op in (Op.A,):
typing.reveal_type(op)
@mypy-play
mypy-play / main.py
Created November 14, 2025 01:37
Shared via mypy Playground
from typing import Any, Generic, TypeVarTuple, TypeVar, Concatenate, Tuple, Unpack, ParamSpec, Optional, TypedDict, Required, NotRequired
T = TypeVar('T')
TT = TypeVarTuple('TT')
TTF = TypeVarTuple('TTF')
P = ParamSpec('P')
class Base():
@classmethod
def do(cls, *args, **kwargs):