From b17f0fcaab83ca0f95099b7a504e34291232e909 Mon Sep 17 00:00:00 2001 From: Hunter Hogan Date: Thu, 2 Apr 2026 23:26:36 -0500 Subject: [PATCH 1/2] [_operator] Type `add` and `sub` mimicking `mul` in #15598. --- stdlib/_operator.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index 83344c7f96c8..78c37b2aafa2 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import SupportsGetItem, SupportsMul, SupportsRMul +from _typeshed import SupportsAdd, SupportsGetItem, SupportsMul, SupportsRAdd, SupportsRMul, SupportsRSub, SupportsSub 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, type_check_only @@ -59,7 +59,10 @@ 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, b, /): ... +@overload +def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ... def and_(a, b, /): ... def floordiv(a, b, /): ... def index(a: SupportsIndex, /) -> int: ... @@ -77,7 +80,10 @@ def or_(a, b, /): ... def pos(a: _SupportsPos[_T_co], /) -> _T_co: ... def pow(a, b, /): ... def rshift(a, b, /): ... -def sub(a, b, /): ... +@overload +def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ... def truediv(a, b, /): ... def xor(a, b, /): ... def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ... From 9cdadc866e5f7986fd038f9345366777a1719405 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 5 Apr 2026 13:28:21 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_operator.pyi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index fd5b8ebd1ecb..e7d85f811531 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -1,5 +1,15 @@ import sys -from _typeshed import SupportsAdd, SupportsGetItem, SupportsMod, SupportsMul, SupportsRAdd, SupportsRMod, SupportsRMul, SupportsRSub, SupportsSub +from _typeshed import ( + SupportsAdd, + SupportsGetItem, + SupportsMod, + SupportsMul, + SupportsRAdd, + SupportsRMod, + SupportsRMul, + SupportsRSub, + SupportsSub, +) 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, type_check_only