Skip to content

Commit a76c3d7

Browse files
committed
Properly type (bytes,bytearray).__mod__
Add date.__rsub__ Add allowlist entries
1 parent 26d38e3 commit a76c3d7

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎stdlib/@tests/stubtest_allowlists/common.txt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ builtins.super.__self__
4343
builtins.super.__self_class__
4444
builtins.super.__thisclass__
4545

46+
# These reverse operator implementations use generated slot wrappers
47+
# returning `NotImplemented`, which is why they aren't defined in typeshed.
48+
builtins.bytearray.__rmod__
49+
builtins.bytes.__rmod__
50+
builtins.frozenset.__rand__
51+
builtins.frozenset.__ror__
52+
builtins.frozenset.__rsub__
53+
builtins.frozenset.__rxor__
54+
builtins.set.__rand__
55+
builtins.set.__ror__
56+
builtins.set.__rsub__
57+
builtins.set.__rxor__
58+
builtins.str.__rmod__
59+
# The following reverse operators are also missing from the Python
60+
# implementation.
61+
datetime.timedelta.__rdivmod__
62+
datetime.timedelta.__rfloordiv__
63+
datetime.timedelta.__rmod__
64+
datetime.timedelta.__rtruediv__
65+
4666
# Undocumented implementation details
4767
email.contentmanager.get_and_fixup_unknown_message_content
4868
email.contentmanager.get_message_content

‎stdlib/builtins.pyi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ from typing import ( # noqa: Y022 # ruff: ignore[deprecated-import]
6666

6767
# we can't import `Literal` from typing or mypy crashes: see #11247
6868
# ruff: ignore[deprecated-import]
69-
from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023
69+
from typing_extensions import Buffer, Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023
7070

7171
if sys.version_info >= (3, 14):
7272
from _typeshed import AnnotateFunc
@@ -826,7 +826,7 @@ class bytes(Sequence[int]):
826826
def __add__(self, value: ReadableBuffer, /) -> bytes: ...
827827
def __mul__(self, value: SupportsIndex, /) -> bytes: ...
828828
def __rmul__(self, value: SupportsIndex, /) -> bytes: ...
829-
def __mod__(self, value: Any, /) -> bytes: ...
829+
def __mod__(self, value: Buffer | SupportsBytes, /) -> bytes: ...
830830
# Incompatible with Sequence.__contains__
831831
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
832832
def __eq__(self, value: object, /) -> bool: ...
@@ -957,7 +957,7 @@ class bytearray(MutableSequence[int]):
957957
def __mul__(self, value: SupportsIndex, /) -> bytearray: ...
958958
def __rmul__(self, value: SupportsIndex, /) -> bytearray: ...
959959
def __imul__(self, value: SupportsIndex, /) -> Self: ...
960-
def __mod__(self, value: Any, /) -> bytes: ...
960+
def __mod__(self, value: Buffer | SupportsBytes, /) -> bytearray: ...
961961
# Incompatible with Sequence.__contains__
962962
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
963963
def __eq__(self, value: object, /) -> bool: ...

‎stdlib/datetime.pyi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class date:
120120
@overload
121121
def __sub__(self, value: timedelta, /) -> Self: ...
122122

123+
def __rsub__(self, value: timedelta) -> Self: ...
124+
123125
def __hash__(self) -> int: ...
124126
def weekday(self) -> int: ...
125127
def isoweekday(self) -> int: ...

0 commit comments

Comments
 (0)