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 collections.abc import Callable | |
| from typing import Protocol, TypeVar | |
| class TGCStatsInfo(Protocol): | |
| gen: int | |
| iid: int | |
| class TInstantMsg(Protocol): | |
| type: str | |
| name: str |
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 ( | |
| Generic, | |
| Literal, | |
| TypeAlias, | |
| overload, | |
| ) | |
| from typing_extensions import ( | |
| TypeVar, | |
| ) |
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 StrEnum, auto | |
| from dataclasses import dataclass | |
| class E(StrEnum): | |
| A = auto() | |
| B = auto() | |
| @dataclass() | |
| class D: | |
| e: E |
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
| #!/usr/bin/env python3 | |
| import sys | |
| # Version check - must be first | |
| if sys.version_info < (3, 14): | |
| logger.info(f"Error: This script requires Python 3.14 or higher. Current version: {sys.version_info.major}.{sys.version_info.minor}") | |
| sys.exit(1) | |
| import asyncio |
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 TypeVar | |
| from functools import singledispatch | |
| #T = TypeVar("T", bound=str | int) # should give errors | |
| T = TypeVar("T", str, int) # should work | |
| @singledispatch | |
| def times_two(v: T) -> T: | |
| raise NotImplementedError |
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 signal | |
| 1 in (i for i in (signal.SIGINT,)) | |
| 1 in [i for i in (signal.SIGINT,)] |
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 signal | |
| 1 in (i for i in (signal.SIGINT,)) | |
| 1 in [i for i in (signal.SIGINT,)] |
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 dataclasses | |
| from functools import partial | |
| from typing import TYPE_CHECKING, TypeAlias | |
| if TYPE_CHECKING: | |
| from dataclasses import dataclass as frozen_nan_safe | |
| else: | |
| def frozen_nan_safe(**kwargs): | |
| assert kwargs['frozen'] | |
| return dataclasses.dataclass(**kwargs) |
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 dataclasses | |
| from functools import partial | |
| from typing import TYPE_CHECKING | |
| if TYPE_CHECKING: | |
| frozen_nan_safe = dataclasses.dataclass | |
| else: | |
| frozen_nan_safe = partial(dataclasses.dataclass, frozen=True) | |
| def test_frozen_decorator() -> None: |
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 Callable, Protocol | |
| ### Example 1: Works as intended. The method is decorated and is | |
| ### callable as usual. | |
| def decorate_method[T](method: Callable[[T], None]) -> Callable[[T], None]: | |
| def _inner(_self: T) -> None: | |
| print('Decorated!') | |
| method(_self) |
NewerOlder