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
# mypy: allow-any-generics | |
from typing import Generator, Any | |
def f() -> Generator: | |
x: str = yield | |
return x | |
def g() -> Generator[Any, Any, Any]: | |
x: str = yield | |
return x |
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 __future__ import annotations | |
from typing import TypeVar, Concatenate, ParamSpec, Any | |
from collections.abc import Callable | |
F = TypeVar("F", bound = Callable[..., Any]) | |
P = ParamSpec("P") | |
R = TypeVar("R") | |
S = TypeVar("S") |
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 __future__ import annotations | |
import datetime | |
import functools | |
import inspect | |
from typing import ( | |
TYPE_CHECKING, | |
Any, | |
Concatenate, | |
Generic, |
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_extensions import TypeIs | |
from typing import Any, Awaitable, TypeVar, Union | |
T = TypeVar('T') | |
def is_awaitable(val: object) -> TypeIs[Awaitable[Any]]: pass | |
def main(a: Union[Awaitable[T], T]) -> None: | |
if is_awaitable(a): | |
reveal_type(a) # N: Revealed type is "Union[typing.Awaitable[T`-1], typing.Awaitable[Any]]" | |
else: | |
reveal_type(a) # N: Revealed type is "T`-1" |
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
# https://peps.python.org/pep-0646/ | |
from typing import Generic, Tuple, List, TypeVarTuple, Unpack | |
class A: | |
... | |
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 | |
from typing import Any, Never, overload | |
class NDArray: | |
shape: tuple | |
def __setitem__(self, idx: NDArray, v: object) -> None: ... | |
def random(x: object) -> NDArray: return NDArray() | |
Image = typing.NewType('Image', NDArray) |
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 overload, Literal | |
@overload | |
def execute_command(command: str, | |
additional_arguments: str = '', | |
*, | |
capture_output: Literal[True], | |
) -> 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 overload, Literal | |
@overload | |
def execute_command(command: str, | |
additional_arguments: str = '', | |
*, | |
capture_output: Literal[True], | |
) -> 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 overload, Literal | |
class Foo: | |
@overload | |
def some_method(self, bar: str = '', *, flag: Literal[True]) -> int: | |
... | |
@overload | |
def some_method(self, bar: str = '', *, flag: Literal[False]) -> list[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
from typing import TypeVar | |
from abc import ABC | |
class A(ABC): | |
def m(self) -> None: | |
print("A") | |
class B(A): | |
def m(self) -> None: | |
print("B") |