Skip to content

Commit 2a09a2b

Browse files
committed
Write small sample of specific operators for proof of concept
1 parent 3e1b90b commit 2a09a2b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

stdlib/_operator.pyi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ from typing_extensions import ParamSpec, TypeAlias, TypeIs
77

88
_R = TypeVar("_R")
99
_T = TypeVar("_T")
10+
_T_contra = TypeVar("_T_contra", contravariant=True)
11+
_U = TypeVar("_U")
12+
_U_co = TypeVar("_U_co", covariant=True)
1013
_T_co = TypeVar("_T_co", covariant=True)
1114
_K = TypeVar("_K")
1215
_V = TypeVar("_V")
@@ -58,14 +61,50 @@ def truth(a: object, /) -> bool: ...
5861
def is_(a: object, b: object, /) -> bool: ...
5962
def is_not(a: object, b: object, /) -> bool: ...
6063
def abs(a: SupportsAbs[_T], /) -> _T: ...
64+
65+
class _SupportsAdd(Protocol[_T_contra, _U_co]):
66+
def __add__(self, other: _T_contra, /) -> _U_co: ...
67+
68+
class _SupportsRAdd(Protocol[_T_contra, _U_co]):
69+
def __radd__(self, other: _T_contra, /) -> _U_co: ...
70+
71+
@overload
72+
def add(a: _SupportsAdd[_T, _U], b: _T, /) -> _U: ...
73+
@overload
74+
def add(a: _T, b: _SupportsRAdd[_T, _U], /) -> _U: ...
75+
@overload
6176
def add(a: Any, b: Any, /) -> Any: ...
77+
78+
class _SupportsAnd(Protocol[_T_contra, _U_co]):
79+
def __and__(self, other: _T_contra, /) -> _U_co: ...
80+
81+
class _SupportsRAnd(Protocol[_T_contra, _U_co]):
82+
def __rand__(self, other: _T_contra, /) -> _U_co: ...
83+
84+
@overload
85+
def and_(a: _SupportsAnd[_T, _U], b: _T, /) -> _U: ...
86+
@overload
87+
def and_(a: _T, b: _SupportsRAnd[_T, _U], /) -> _U: ...
88+
@overload
6289
def and_(a: Any, b: Any, /) -> Any: ...
6390
def floordiv(a: Any, b: Any, /) -> Any: ...
6491
def index(a: SupportsIndex, /) -> int: ...
6592
def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ...
6693
def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ...
6794
def lshift(a: Any, b: Any, /) -> Any: ...
6895
def mod(a: Any, b: Any, /) -> Any: ...
96+
97+
class _SupportsMul(Protocol[_T_contra, _U_co]):
98+
def __mul__(self, other: _T_contra, /) -> _U_co: ...
99+
100+
class _SupportsRMul(Protocol[_T_contra, _U_co]):
101+
def __rmul__(self, other: _T_contra, /) -> _U_co: ...
102+
103+
@overload
104+
def mul(a: _SupportsMul[_T, _U], b: _T, /) -> _U: ...
105+
@overload
106+
def mul(a: _T, b: _SupportsRMul[_T, _U], /) -> _U: ...
107+
@overload
69108
def mul(a: Any, b: Any, /) -> Any: ...
70109
def matmul(a: Any, b: Any, /) -> Any: ...
71110
def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ...

0 commit comments

Comments
 (0)