From 1694864d015543f147f1bcf2e7ba28321eb2e666 Mon Sep 17 00:00:00 2001 From: Lehmaning <60032845+Lehmaning@users.noreply.github.com> Date: Sat, 5 Apr 2025 14:29:06 +0800 Subject: [PATCH] Improve stubs for `operator` --- stdlib/_operator.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index 967215d8fa21..5bcf17f47db0 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import SupportsGetItem +from _typeshed import SupportsAdd, SupportsGetItem, SupportsMul from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload @@ -8,6 +8,7 @@ from typing_extensions import ParamSpec, TypeAlias, TypeIs _R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) +_T_contra = TypeVar("_T_contra", contravariant=True) _K = TypeVar("_K") _V = TypeVar("_V") _P = ParamSpec("_P") @@ -51,7 +52,7 @@ def truth(a: object, /) -> bool: ... def is_(a: object, b: object, /) -> bool: ... def is_not(a: object, b: object, /) -> bool: ... def abs(a: SupportsAbs[_T], /) -> _T: ... -def add(a: Any, b: Any, /) -> Any: ... +def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... def and_(a: Any, b: Any, /) -> Any: ... def floordiv(a: Any, b: Any, /) -> Any: ... def index(a: SupportsIndex, /) -> int: ... @@ -59,7 +60,7 @@ def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ... def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ... def lshift(a: Any, b: Any, /) -> Any: ... def mod(a: Any, b: Any, /) -> Any: ... -def mul(a: Any, b: Any, /) -> Any: ... +def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... def matmul(a: Any, b: Any, /) -> Any: ... def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ... def or_(a: Any, b: Any, /) -> Any: ...