This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]: | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import * | |
| T = TypeVar("T", bound=int | float) | |
| class Adder(Protocol[T]): | |
| def add(self, x: T, y: T) -> T: | |
| ... | |
| class IntAdder(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from enum import Enum, auto | |
| class Thing(Enum): | |
| ONE = auto() | |
| def main(foo: Thing) -> None: | |
| print(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from enum import Enum, auto | |
| class Thing(Enum): | |
| ONE = auto() | |
| def main(foo: Thing) -> None: | |
| print(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from enum import Enum, auto | |
| class Thing(Enum): | |
| ONE = auto() | |
| def main(foo: Thing) -> None: | |
| print(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from enum import Enum, auto | |
| class Thing(Enum): | |
| ONE = auto() | |
| async def main(foo: Thing) -> None: | |
| print(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from enum import Enum, auto | |
| class Thing(Enum): | |
| ONE = auto() | |
| async def main(foo: Thing) -> None: | |
| print(obj) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import NotRequired, TypedDict | |
| class Foo(TypedDict): | |
| key1: NotRequired[str] | |
| key2: NotRequired[int] | |
| foo = Foo() | |
| for key in "key1", "key2": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import enum | |
| import typing | |
| class Op(enum.Enum): | |
| A = "a" | |
| B = "b" | |
| def run(op: Op): | |
| if op in (Op.A,): | |
| typing.reveal_type(op) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any, Generic, TypeVarTuple, TypeVar, Concatenate, Tuple, Unpack, ParamSpec, Optional, TypedDict, Required, NotRequired | |
| T = TypeVar('T') | |
| TT = TypeVarTuple('TT') | |
| TTF = TypeVarTuple('TTF') | |
| P = ParamSpec('P') | |
| class Base(): | |
| @classmethod | |
| def do(cls, *args, **kwargs): |
NewerOlder