Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created January 22, 2026 20:11
Shared via mypy Playground
a = { 10 }
b = { 20 }
print( ( a or [] ) + ( b or [] ) )
@mypy-play
mypy-play / main.py
Created January 22, 2026 20:08
Shared via mypy Playground
a = [ 10 ]
b = { 20 }
print( ( a or [] ) + ( b or [] ) )
@mypy-play
mypy-play / main.py
Created January 22, 2026 20:08
Shared via mypy Playground
a = [ 10 ]
b = { 20 }
print( a + b )
@mypy-play
mypy-play / main.py
Created January 22, 2026 17:39
Shared via mypy Playground
from typing import ClassVar, Final, Self, Any
class Interface:
# Every subclass has a _name attribute (set by __init_subclass__)
_name: ClassVar[Final[str]]
# Registry of subclasses
@mypy-play
mypy-play / main.py
Created January 22, 2026 17:34
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 January 22, 2026 16:06
Shared via mypy Playground
cond = False
print(1, *([2] if cond else []), 3)
@mypy-play
mypy-play / main.py
Created January 22, 2026 15:37
Shared via mypy Playground
from typing import Protocol, Callable
# --- workflow contracts (the only supported implementation style) ---
class SayHelloWorkflow(Protocol):
def run(self, name: str) -> str: ...
# A benefit to this class-based approach to defining workflows over the Go
# SDK is that we can also raise type errors for missing query or signal
@mypy-play
mypy-play / main.py
Created January 22, 2026 14:43
Shared via mypy Playground
from __future__ import annotations
from dataclasses import dataclass
from typing import Protocol
# --- "generated" RPC types (pretend these come from codegen) ---
@dataclass(frozen=True)
class HelloRequest:
@mypy-play
mypy-play / main.py
Created January 22, 2026 13:48
Shared via mypy Playground
import uuid
from typing import reveal_type
x = uuid.uuid4()
reveal_type(x)
@mypy-play
mypy-play / main.py
Created January 22, 2026 12:55
Shared via mypy Playground
from typing import Any
def fn(**kwargs: dict[str, Any]):
...
fn(param=[1,2,3])