Skip to content

Instantly share code, notes, and snippets.

@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
@mypy-play
mypy-play / main.py
Created March 12, 2026 11:57
Shared via mypy Playground
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from enum import Enum
from typing import assert_never
class A(Enum):
A0 = "0"
A1 = "1"
@mypy-play
mypy-play / main.py
Created March 12, 2026 06:07
Shared via mypy Playground
type atype = ().__class__.__class__[().__class__.__class__[().__class__.__mro__[-1]]]
@mypy-play
mypy-play / main.py
Created March 12, 2026 04:33
Shared via mypy Playground
from typing import TypeVar, Generic
from collections.abc import Callable
BaseExcT_co = TypeVar("BaseExcT_co", bound=BaseException, covariant=True)
BaseExcT_co_default = TypeVar(
"BaseExcT_co_default", bound=BaseException, covariant=True, default=BaseException
)
class RaisesExc(Generic[BaseExcT_co_default]):
@mypy-play
mypy-play / main.py
Created March 11, 2026 04:36
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 10, 2026 20:22
Shared via mypy Playground
reveal_type(1)