Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created November 16, 2025 00:57
Show Gist options
  • Select an option

  • Save mypy-play/4def4c12274e6fce75d274f043c099c1 to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/4def4c12274e6fce75d274f043c099c1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from dataclasses import dataclass
from typing import TYPE_CHECKING, TypeVar, dataclass_transform, Protocol
from functools import partial
if TYPE_CHECKING:
T = TypeVar('T')
@dataclass_transform(frozen_default = True)
def frozen(cls: type[T]) -> type[T]:
...
else:
frozen = dataclass
@frozen
class Foo:
x: int
y: int
foo = Foo(1, 2)
class Bar(Protocol):
x: int
def bar(bar: Bar): ...
bar(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment