Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created February 13, 2026 22:24
Shared via mypy Playground
from typing import Iterator
def fib(n: int) -> Iterator[int]:
a, b = 0, 1
while a < n:
yield a
a, b = b, a + b
@mypy-play
mypy-play / main.py
Created February 13, 2026 16:48
Shared via mypy Playground
class A:
def __new__(cls) -> int:
return 42
reveal_type(A())
@mypy-play
mypy-play / main.py
Created February 13, 2026 00:23
Shared via mypy Playground
class A:
def go(self) -> None:
pass
class B0:
X: type[A] | None = None
class B(B0):
X = A
@mypy-play
mypy-play / main.py
Created February 12, 2026 15:06
Shared via mypy Playground
from typing import Callable, TypeVar
_K = TypeVar("_K")
_V = TypeVar("_V")
class Foo:
pass
class Util:
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:58
Shared via mypy Playground
from abc import ABC, abstractmethod
import typing as t
class nmBaseConfig:
...
class nmLSFConfig(nmBaseConfig):
...
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:56
Shared via mypy Playground
from typing import Callable, TypeVar
_K = TypeVar("_K")
_V = TypeVar("_V")
class Foo:
pass
class Util:
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:50
Shared via mypy Playground
from typing import Callable, TypeVar
_K = TypeVar("_K")
_V = TypeVar("_V")
class Foo:
pass
class Util:
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:43
Shared via mypy Playground
from typing import ClassVar
from enum import IntEnum
class WithDocReference:
_doc_reference: ClassVar[str]
class MyEnum(WithDocReference, IntEnum):
_doc_reference = "https://www.google.com"
A = 1
B = 2
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:06
Shared via mypy Playground
from typing import Any, Protocol, assert_type
class WithTuple[*Ts](Protocol):
tup: tuple[*Ts]
def get_tuple[*Ts](e: WithTuple[*Ts]) -> tuple[*Ts]:
return e.tup
@mypy-play
mypy-play / main.py
Created February 12, 2026 14:02
Shared via mypy Playground
from typing import Protocol, runtime_checkable
class P(Protocol):
def f(self) -> None: ...
@runtime_checkable
class RCP(Protocol):
def f(self) -> None: ...