This file contains 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
# Sentinel to denote unset values | |
UNSET = object() | |
def foo(timezone: str | object | None = UNSET) -> None: | |
pass | |
if __name__ == "__main__": | |
foo() |
This file contains 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 typing_extensions import TypeIs | |
_T = TypeVar('_T', str, int) | |
def is_str(val: str | int) -> TypeIs[str]: | |
return isinstance(val, str) | |
This file contains 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, TypedDict, Generic | |
VarT = TypeVar("VarT", bound=dict) | |
class MyCls(Generic[VarT]): | |
def sneed(self, t: VarT): | |
print(t) | |
class MyDict(TypedDict): | |
a: int |
This file contains 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 typing | |
SingleItem = typing.Tuple[int] | |
MultipleItems = typing.Tuple[int, ...] | |
def test(a: SingleItem, b: MultipleItems) -> None: | |
return | |
This file contains 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, Generic, Any, cast, overload | |
from abc import abstractmethod, ABC | |
_TP = TypeVar("_TP", bound=tuple[Any, ...]) | |
class Select(Generic[_TP]): | |
pass | |
This file contains 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, Generic, Any, cast | |
from abc import abstractmethod, ABC | |
_TP = TypeVar("_TP", bound=tuple[Any, ...]) | |
_TM = TypeVar("_TM") | |
class Select(Generic[_TP]): | |
pass |
This file contains 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, Generic, Any, cast | |
from abc import abstractmethod, ABC | |
_TP = TypeVar("_TP", bound=tuple[Any, ...]) | |
_TM = TypeVar("_TM") | |
class Select(Generic[_TP]): | |
pass |
This file contains 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 typing | |
def f() -> typing.Annotated[int, "this is da' sh..."]: | |
return 0 | |
x: int = f() | |
reveal_type(f()) |
This file contains 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 typing | |
def f() -> typing.Annotated[int, "this is da' sh..."]: | |
return 0 | |
x: int = f() |
This file contains 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 typing_extensions import TypeIs | |
_T = TypeVar('_T', str, int) | |
def is_str(val: str | int) -> TypeIs[str]: | |
return isinstance(val, str) | |