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, Literal | |
| A = TypeVar("A") | |
| B = TypeVar("B") | |
| MutExResult = tuple[Literal["neither"], None, None] | tuple[Literal["both"], A, B] | tuple[Literal["left"], A, None] | tuple[Literal["right"], None, B] | |
| def check_mutually_exclusive(a: A | None, b: B | None) -> MutExResult[A, B]: | |
| if a is None and b is 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
| import dataclasses | |
| @dataclasses.dataclass | |
| class Base: | |
| def fn(self, a: int) -> int: | |
| return a | |
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 TypeVar, Generic, Callable, Dict, Any | |
| import sys | |
| T_Input = TypeVar("T_Input") | |
| class _RegisteredType(Generic[T_Input]): | |
| def __init__(self, name: str): | |
| self.name = name |
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, TypeVar, Literal | |
| from dataclasses import dataclass | |
| T = TypeVar('T') | |
| class RequestTypeToken(Generic[T]): | |
| """Token that proves a request type has been registered.""" | |
| def __init__(self, type_name: T): | |
| self.name = type_name | |
| print(type(type_name)) |
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, Literal, NotRequired, TypedDict, final | |
| # @final | |
| class InputPromptJSON(TypedDict): | |
| """JSON format representing the input text to an LLM completion. | |
| This may evolve over time as we add support for tools and other features. | |
| """ | |
| # New rows should always use an array of blocks, even if the application code just gave a string. |
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 | |
| @dataclass | |
| class A: | |
| a: int | |
| @dataclass(slots=True) | |
| class ASlot: | |
| a: 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 typing import Iterable | |
| def fun[T](values: Iterable[T], value: list[T]) -> tuple[T | None, T | None]: | |
| ... | |
| return None, None | |
| values: Iterable[int] | |
| my_list: list[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 __future__ import annotations | |
| from typing import TypeVar | |
| T = TypeVar("T", bound=str | int) | |
| VALUES: dict[str, str] = {"SIZE": "100", "ADDR": "0x100", "NAME": "potato"} | |
| def get_parameter(parameter: str, _rtype: type[T]) -> T: | |
| """Get the parameter""" | |
| if parameter.startswith("N"): |
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 __future__ import annotations | |
| from typing import TypeVar | |
| T = TypeVar("T", bound=str | int) | |
| def get_parameter(parameter: str, _rtype: type[T]) -> T: | |
| """Get the parameter""" | |
| if parameter == "SIZE": | |
| return 5 |
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 __future__ import annotations | |
| from typing import TypeVar | |
| VALUES: dict[str, str] = {"SIZE": "100", "ADDR": "0x100", "NAME": "potato"} | |
| T = TypeVar("T", bound=str | int) | |
| def get_parameter(parameter: str, _rtype: type[T]) -> T: | |
| """Get the parameter""" |
NewerOlder