Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created February 11, 2026 16:09
Shared via mypy Playground
import typing
class _Int(int):
_min: typing.ClassVar[int]
_max: typing.ClassVar[int]
_code: typing.ClassVar[str]
def __new__(cls, value: int) -> _Int:
@mypy-play
mypy-play / main.py
Created February 11, 2026 16:00
Shared via mypy Playground
from typing import Protocol, Any
class Result:
def __init__(self, foo):
self.foo = foo
class MyInterface(Protocol):
@mypy-play
mypy-play / main.py
Created February 11, 2026 15:43
Shared via mypy Playground
from typing import Protocol, Any
class Result:
pass
class MyInterface(Protocol):
def foo(self) -> Result: ...
@mypy-play
mypy-play / main.py
Created February 11, 2026 15:25
Shared via mypy Playground
from typing import Optional
class Node:
data: int
left: Optional[Node]
right: Optional[Node]
def __init__(self, data: int)-> None:
@mypy-play
mypy-play / main.py
Created February 11, 2026 15:24
Shared via mypy Playground
from typing import Optional
class Node:
data: int
left: Optional[Node]
right: Optional[Node]
def __init__(self, data: int)-> None:
@mypy-play
mypy-play / main.py
Created February 11, 2026 15:11
Shared via mypy Playground
from typing import TypedDict
class TD1(TypedDict):
a: int
b: str
class TD2(TypedDict):
a: str
c: int
@mypy-play
mypy-play / main.py
Created February 11, 2026 15:06
Shared via mypy Playground
from typing import TypedDict
class TD1(TypedDict):
a: int
b: str
class TD2(TypedDict):
a: str
c: int
@mypy-play
mypy-play / main.py
Created February 11, 2026 10:09
Shared via mypy Playground
from typing import Callable
add_one: Callable[[int], int] = lambda x: x + 1
add_two: Callable[[int], int] = lambda x: str(x)
@mypy-play
mypy-play / main.py
Created February 11, 2026 09:56
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 11, 2026 05:02
Shared via mypy Playground
from __future__ import annotations
import typing as ty
if ty.TYPE_CHECKING:
import numpy as np
def foo(bar: list | np.ndarray[tuple[int]]) -> list:
return []