Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created September 3, 2025 04:42
Shared via mypy Playground
class Meta(type):
def m(cls) -> int:
return 0
def __add__(cls, other) -> int:
return 0
class A(metaclass=Meta):
@classmethod
def m(cls) -> str:
@mypy-play
mypy-play / main.py
Created September 2, 2025 23:48
Shared via mypy Playground
from typing import Callable, Coroutine
from logging import getLogger
logger = getLogger(__name__)
class StatsD:
def increment(self, metric: str) -> None:
...
@mypy-play
mypy-play / main.py
Created September 2, 2025 20:04
Shared via mypy Playground
import dataclasses
import pymock
@dataclasses.dataclass(frozen=True)
class F:
a: int = 4
b: float = 1/a
@dataclasses.dataclass(frozen=True)
class G:
@mypy-play
mypy-play / main.py
Created September 2, 2025 16:11
Shared via mypy Playground
import itertools
import typing as t
from collections import abc
from pathlib import Path
class PackageSpec(t.NamedTuple):
package_name: str
locked_ver: str | None
@mypy-play
mypy-play / main.py
Created September 2, 2025 12:30
Shared via mypy Playground
class MyClass:
_my_field: int
def __init__(self) -> None:
pass
def foo(self) -> int:
return self._my_field # Используется не инициализированной.
@mypy-play
mypy-play / main.py
Created September 2, 2025 12:17
Shared via mypy Playground
from typing import reveal_type
def non_optional[T](value: T|None)->T:
assert value is not None
return value
def f(x: int|None):
reveal_type(x)
y = non_optional(x)
reveal_type(y)
@mypy-play
mypy-play / main.py
Created September 2, 2025 11:05
Shared via mypy Playground
options: list[tuple[int, *tuple[str, ...]]] = [(1, 'a'), (2, 'b', 'c')]
for i, *s in options:
print(hex(i), '_'.join(s))
@mypy-play
mypy-play / main.py
Created September 2, 2025 10:44
Shared via mypy Playground
for i, s in [(1, ('a',)), (2, ('b', 'c'))]:
print(hex(i), '_'.join(s))
@mypy-play
mypy-play / main.py
Created September 2, 2025 10:39
Shared via mypy Playground
options: list[tuple[int, *tuple[str, ...]]] = [(1, 'a'), (2, 'b', 'c')]
for i, *s in options:
print(hex(i), '_'.join(s))
@mypy-play
mypy-play / main.py
Created September 2, 2025 10:37
Shared via mypy Playground
for i, *s in [(1, 'a'), (2, 'b', 'c')]:
print(hex(i), '_'.join(s))