Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created July 11, 2026 12:50
Shared via mypy Playground
def ft_harvest_total():
x = int(input("Day 1 harvest: "))
y = int(input("Day 2 harvest: "))
z = int(input("Day 3 harvest: "))
print("Total harvest:", x + y + z)
@mypy-play
mypy-play / main.py
Created July 10, 2026 17:38
Shared via mypy Playground
class C:
pass
def foo(self) -> int:
return 10
C.foo = foo
@mypy-play
mypy-play / main.py
Created July 10, 2026 13:10
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 July 10, 2026 06:34
Shared via mypy Playground
from collections.abc import Callable, Hashable, Mapping
from typing import Concatenate, Any
class NDArray: ...
def mean(_: NDArray, *args: Any, **kwargs: Any) -> Any:
pass
def f(_: Mapping[Hashable, list[Callable[Concatenate[NDArray, ...], Any]]]) -> None:
pass
@mypy-play
mypy-play / main.py
Created July 9, 2026 11:10
Shared via mypy Playground
from typing import Protocol, TypeVar, ClassVar, Any
from collections.abc import Iterator
_T_co = TypeVar("_T_co", covariant=True)
class CovariantList(Protocol[_T_co]):
__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
@property # type: ignore[override]
def __class__(self) -> type[list[Any]]: ... # pyrefly: ignore[bad-override]
@__class__.setter
@mypy-play
mypy-play / main.py
Created July 8, 2026 19:49
Shared via mypy Playground
import typing
from typing import Any
class RunnerSnapshot:
pass
@typing.overload
def _normalize_runner(runner: dict) -> RunnerSnapshot:
@mypy-play
mypy-play / main.py
Created July 8, 2026 13:13
Shared via mypy Playground
from dataclasses import dataclass
from typing import Any, NotRequired, Self, TypedDict
@dataclass
class BaseQueryParameters:
type: str
query: str
from_: int
size: int
@mypy-play
mypy-play / main.py
Created July 8, 2026 09:29
Shared via mypy Playground
from typing_extensions import TypeForm
def foo[T](x: TypeForm[T]) -> None:
pass
foo("Unresolvable")
@mypy-play
mypy-play / main.py
Created July 8, 2026 09:23
Shared via mypy Playground
import typing as tp
from typing import reveal_type
class MyIntList:
def __init__(self, lst: list[int]) -> None:
self.lst = lst
@tp.overload
@mypy-play
mypy-play / main.py
Created July 7, 2026 19:28
Shared via mypy Playground
from __future__ import annotations
from typing import overload
class Widget:
@overload
def __init__(self, name: str, /, major: int, minor: int, *, extra: object = None, config: str | None = None) -> None: ...
@overload
def __init__(self, *, name: str, major: int, minor: int, extra: object = None, config: str | None = None) -> None: ...
@overload