From 575a008744af067b40db33985b9f3a1397e90d8e Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Sat, 27 Nov 2021 17:43:17 +0300 Subject: [PATCH] Add `operator.call()` and `operator.__call__()` for Python 3.11 (#6396) Co-authored-by: Akuli --- stdlib/_operator.pyi | 4 ++++ stdlib/operator.pyi | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index bea438861..0e18a01fb 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -1,4 +1,5 @@ # In reality the import is the other way around, but this way we can keep the operator stub in 2and3 +import sys from operator import ( abs as abs, add as add, @@ -57,4 +58,7 @@ from operator import ( ) from typing import AnyStr +if sys.version_info >= (3, 11): + from operator import call as call + def _compare_digest(__a: AnyStr, __b: AnyStr) -> bool: ... diff --git a/stdlib/operator.pyi b/stdlib/operator.pyi index 45953d429..5a20cd18a 100644 --- a/stdlib/operator.pyi +++ b/stdlib/operator.pyi @@ -1,5 +1,7 @@ +import sys from typing import ( Any, + Callable, Container, Generic, Mapping, @@ -11,12 +13,14 @@ from typing import ( TypeVar, overload, ) -from typing_extensions import SupportsIndex, final +from typing_extensions import ParamSpec, SupportsIndex, final +_R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _K = TypeVar("_K") _V = TypeVar("_V") +_P = ParamSpec("_P") def lt(__a: Any, __b: Any) -> Any: ... def le(__a: Any, __b: Any) -> Any: ... @@ -177,3 +181,7 @@ def itruediv(__a: Any, __b: Any) -> Any: ... def __itruediv__(a: Any, b: Any) -> Any: ... def ixor(__a: Any, __b: Any) -> Any: ... def __ixor__(a: Any, b: Any) -> Any: ... + +if sys.version_info >= (3, 11): + def call(__obj: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ... # type: ignore + def __call__(obj: Callable[_P, _R], *args: _P.args, **kwargs: _P.kwargs) -> _R: ... # type: ignore