Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created March 15, 2026 20:56
Shared via mypy Playground
print()
@mypy-play
mypy-play / main.py
Created March 15, 2026 20:14
Shared via mypy Playground
class Hard:
pass
class Soft:
pass
lst: list[Hard] | list[Soft]
lst = [val for val in lst]
@mypy-play
mypy-play / main.py
Created March 15, 2026 15:12
Shared via mypy Playground
class Hard:
pass
class Soft:
pass
lst: list[Hard] | list[Soft]
lst = [val for val in lst]
@mypy-play
mypy-play / main.py
Created March 15, 2026 12:58
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 March 14, 2026 12:44
Shared via mypy Playground
from typing import Iterator, Literal
def fib[T: Literal[10,11]](n: T) -> Iterator[int]:
a, b = 0, 1
while a < n:
yield a
a, b = b, a + b
fib[10](10)
@mypy-play
mypy-play / main.py
Created March 12, 2026 23:21
Shared via mypy Playground
def f(x, y) -> None:
z: str = 0
reveal_type((x, y))
def g(x: int, y: str):
z: str = 0
reveal_type((x, y))
def h(x, y):
z: str = 0
@mypy-play
mypy-play / main.py
Last active March 12, 2026 16:32
Shared via mypy Playground
import typing
class P(typing.Protocol):
def foo(self, a: int) -> None: ...
class C:
def foo(self, *args: int) -> None: pass
def f(o: P) -> None:
@mypy-play
mypy-play / main.py
Created March 12, 2026 16:32
Shared via mypy Playground
import typing
class P(typing.Protocol):
def foo(self, a: int) -> None: ...
class C:
def foo(self, *args: int) -> None: pass
def f(o: P) -> None:
@mypy-play
mypy-play / main.py
Created March 12, 2026 16:31
Shared via mypy Playground
import typing
class P(typing.Protocol):
def foo(self, a: int) -> None: ...
class C:
def foo(self, *args: int) -> None: pass
def f(o: P) -> None:
@mypy-play
mypy-play / main.py
Created March 12, 2026 16:15
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