Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion stdlib/@tests/test_cases/check_functools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from functools import cache, cached_property, lru_cache, singledispatchmethod, update_wrapper, wraps
from functools import cache, cached_property, lru_cache, partial, singledispatchmethod, update_wrapper, wraps
from typing import Callable, ParamSpec, TypeVar
from typing_extensions import assert_type

Expand Down Expand Up @@ -194,6 +194,20 @@ def method(self) -> Child:
return Child()


def _returns_child() -> Child:
return Child()


def _accept_parent_partial(p: partial[Parent]) -> None:
assert_type(p(), Parent)


def check_partial_covariance() -> None:
p_child = partial(_returns_child)
assert_type(p_child, partial[Child])
_accept_parent_partial(p_child)


class Formatter:
@singledispatchmethod
def format(self, value: object) -> str:
Expand Down
10 changes: 5 additions & 5 deletions stdlib/functools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ def total_ordering(cls: type[_T]) -> type[_T]: ...
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsAllComparisons]: ...

@disjoint_base
class partial(Generic[_T]):
class partial(Generic[_T_co]):
@property
def func(self) -> Callable[..., _T]: ...
def func(self) -> Callable[..., _T_co]: ...
@property
def args(self) -> tuple[Any, ...]: ...
@property
def keywords(self) -> dict[str, Any]: ...
def __new__(cls, func: Callable[..., _T], /, *args: Any, **kwargs: Any) -> Self: ...
def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ...
def __new__(cls, func: Callable[..., _T_co], /, *args: Any, **kwargs: Any) -> Self: ...
def __call__(self, /, *args: Any, **kwargs: Any) -> _T_co: ...
if sys.version_info >= (3, 14):
@overload
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
@overload
def __get__(self, instance: object, owner: type[Any] | None = None, /) -> Callable[..., _T]: ...
def __get__(self, instance: object, owner: type[Any] | None = None, /) -> Callable[..., _T_co]: ...

def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

Expand Down
Loading