Created
May 21, 2025 18:53
-
-
Save AlexWaygood/250fb97a731b162f2ab57f6156d1954a to your computer and use it in GitHub Desktop.
`functools.partial` typing
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 sys | |
from types import GenericAlias | |
from typing import Any, Callable, Concatenate, overload | |
class partial[**P1, **P2, T, R, *Ts]: | |
@overload | |
def __new__(cls, func: Callable[P1, R], /) -> partial[P1, P1, Any, R]: ... | |
@overload | |
def __new__(cls, func: Callable[Concatenate[*Ts, P2], R], /, *args: *Ts) -> partial[Concatenate[*Ts, P2], P2, Any, R, *Ts]: ... | |
@overload | |
def __new__(cls, func: Callable[P1, R], /, *args: *Ts, **kwargs: T) -> partial[P1, ..., T, R, *Ts]: ... | |
def __call__(self, *args: P2.args, **kwargs: P2.kwargs) -> R: ... | |
@property | |
def func(self) -> Callable[P1, R]: ... | |
@property | |
def args(self) -> tuple[*Ts]: ... | |
@property | |
def keywords(self) -> dict[str, T]: ... | |
if sys.version_info >= (3, 9): | |
def __class_getitem__(cls, item: Any) -> GenericAlias: ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment