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
| def f(items: list[str]) -> None: | |
| for item in items: | |
| if item == "a": | |
| x = 1 | |
| else: | |
| print(x) |
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 os | |
| def f(u: str | os.PathLike[str]) -> str: | |
| if u and (u := str(u)): | |
| return u | |
| return "" |
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 Final | |
| @dataclass | |
| class Wrapper[T]: | |
| obj: Final[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 Generic, Literal, overload | |
| from typing_extensions import TypeVar | |
| _S = TypeVar("_S", contravariant=True) | |
| _G = TypeVar("_G", covariant=True) | |
| class Base(Generic[_S, _G]): | |
| @overload | |
| def __init__(self, *, null: Literal[False] = False) -> 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 Optional | |
| class A: | |
| pass | |
| def fib() -> Optional[A]: | |
| return |
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 assert_type | |
| class Base: | |
| def __lt__(self, other: "Base") -> str: | |
| return "lt" | |
| class Child(Base): | |
| def __gt__(self, other: "Child") -> int: |
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 InitVar, dataclass | |
| from typing import overload | |
| @dataclass | |
| class Record: | |
| value: InitVar[int] | |
| @overload | |
| def __post_init__(self, value: int) -> 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 assert_type | |
| class LeftMeta(type): | |
| def __mul__(cls, other: object) -> int: | |
| return 1 | |
| class RightMeta(LeftMeta): | |
| def __rmul__(cls, other: object) -> 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 collections.abc import Callable | |
| from typing import assert_type | |
| class Foo[*Ts, **P = [float, bool]]: | |
| def args(self) -> tuple[*Ts]: | |
| raise NotImplementedError | |
| def fn(self) -> Callable[P, None]: | |
| 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
| from types import EllipsisType | |
| from typing import overload | |
| @overload | |
| def func(): ... | |
| @overload | |
| def func(arg: int): ... | |
| def func(arg: int | EllipsisType = ...): | |
| if arg is ...: |
NewerOlder