Skip to content

Commit c333d5d

Browse files
authored
Update mypy to 2.4.0 (#16502)
Fix a few built-in dunder annotations: * Accept `object` instead of `Any` for `str.__mod__`. (Will call `str` on arbitrary objects passed in.) * Add `str.__rmod__`. * Type argument to `{bytes,bytearray}.__mod__` (was `Any`). * Add `{bytes,bytesarray}.__rmod__`. * Add reverse operators to `set` and `frozenset`. * Add `types.FrameLocalsProxyType.__{i,r,}or__`.
1 parent c4b5c1c commit c333d5d

6 files changed

Lines changed: 72 additions & 10 deletions

File tree

‎requirements-tests.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Type checkers that we test our stubs against. These should always
22
# be pinned to a specific version to make failure reproducible.
3-
mypy==2.3.1
3+
mypy==2.4.0
44
pyrefly==1.3.2
55
pyright==1.1.414
66
ty==0.0.84

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

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

46+
# The following reverse operators are present in the C implementation
47+
# (probably incidental), but missing from the Python implementation.
48+
datetime.date.__rsub__
49+
datetime.datetime.__rsub__
50+
datetime.timedelta.__rdivmod__
51+
datetime.timedelta.__rfloordiv__
52+
datetime.timedelta.__rmod__
53+
datetime.timedelta.__rtruediv__
54+
4655
# Undocumented implementation details
4756
email.contentmanager.get_and_fixup_unknown_message_content
4857
email.contentmanager.get_message_content

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
dataclasses.MISSING
66
dataclasses._MISSING_TYPE
7-
dataclasses.field
87

98
# =============================================================
109
# Allowlist entries that cannot or should not be fixed; >= 3.15
1110
# =============================================================
1211

1312
# runtime default is a list object used as a sentinel
1413
base64.b64decode
15-
urllib.parse.urlunparse
16-
urllib.parse.urlunsplit
1714

1815
# Internal implementation details of the sampling profiler.
1916
profiling.sampling.binary_collector

‎stdlib/builtins.pyi‎

Lines changed: 56 additions & 4 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
@@ -711,7 +711,9 @@ class str(Sequence[str]):
711711
@overload
712712
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
713713
@overload
714-
def __mod__(self, value: Any, /) -> str: ...
714+
def __mod__(self, value: object, /) -> str: ...
715+
716+
def __rmod__(self, value: str, /) -> str: ...
715717

716718
@overload
717719
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@@ -826,7 +828,8 @@ class bytes(Sequence[int]):
826828
def __add__(self, value: ReadableBuffer, /) -> bytes: ...
827829
def __mul__(self, value: SupportsIndex, /) -> bytes: ...
828830
def __rmul__(self, value: SupportsIndex, /) -> bytes: ...
829-
def __mod__(self, value: Any, /) -> bytes: ...
831+
def __mod__(self, value: Buffer | SupportsBytes | tuple[Buffer | SupportsBytes, ...], /) -> bytes: ...
832+
def __rmod__(self, value: bytes, /) -> bytes: ...
830833
# Incompatible with Sequence.__contains__
831834
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
832835
def __eq__(self, value: object, /) -> bool: ...
@@ -957,7 +960,8 @@ class bytearray(MutableSequence[int]):
957960
def __mul__(self, value: SupportsIndex, /) -> bytearray: ...
958961
def __rmul__(self, value: SupportsIndex, /) -> bytearray: ...
959962
def __imul__(self, value: SupportsIndex, /) -> Self: ...
960-
def __mod__(self, value: Any, /) -> bytes: ...
963+
def __mod__(self, value: Buffer | SupportsBytes | tuple[Buffer | SupportsBytes, ...], /) -> bytearray: ...
964+
def __rmod__(self, value: bytearray, /) -> bytearray: ...
961965
# Incompatible with Sequence.__contains__
962966
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
963967
def __eq__(self, value: object, /) -> bool: ...
@@ -1457,12 +1461,36 @@ class set(MutableSet[_T]):
14571461
def __iter__(self) -> Iterator[_T]: ...
14581462
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
14591463
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
1464+
1465+
@overload
1466+
def __rand__(self, value: set[_S], /) -> set[_S]: ...
1467+
@overload
1468+
def __rand__(self, value: frozenset[_S], /) -> frozenset[_S]: ...
1469+
14601470
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
14611471
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1472+
1473+
@overload
1474+
def __ror__(self, value: set[_S], /) -> set[_T | _S]: ...
1475+
@overload
1476+
def __ror__(self, value: frozenset[_S], /) -> frozenset[_T | _S]: ...
1477+
14621478
def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
14631479
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
1480+
1481+
@overload
1482+
def __rsub__(self, value: set[_S], /) -> set[_S]: ...
1483+
@overload
1484+
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...
1485+
14641486
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
14651487
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1488+
1489+
@overload
1490+
def __rxor__(self, value: set[_S], /) -> set[_T | _S]: ...
1491+
@overload
1492+
def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T | _S]: ...
1493+
14661494
def __le__(self, value: AbstractSet[object], /) -> bool: ...
14671495
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
14681496
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
@@ -1490,9 +1518,33 @@ class frozenset(AbstractSet[_T_co]):
14901518
def __contains__(self, o: object, /) -> bool: ...
14911519
def __iter__(self) -> Iterator[_T_co]: ...
14921520
def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
1521+
1522+
@overload
1523+
def __rand__(self, value: set[_S], /) -> set[_S]: ...
1524+
@overload
1525+
def __rand__(self, value: frozenset[_S], /) -> frozenset[_S]: ...
1526+
14931527
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1528+
1529+
@overload
1530+
def __ror__(self, value: set[_S], /) -> set[_T_co | _S]: ...
1531+
@overload
1532+
def __ror__(self, value: frozenset[_S], /) -> frozenset[_T_co | _S]: ...
1533+
14941534
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
1535+
1536+
@overload
1537+
def __rsub__(self, value: set[_S], /) -> set[_S]: ...
1538+
@overload
1539+
def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ...
1540+
14951541
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1542+
1543+
@overload
1544+
def __rxor__(self, value: set[_S], /) -> set[_T_co | _S]: ...
1545+
@overload
1546+
def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T_co | _S]: ...
1547+
14961548
def __le__(self, value: AbstractSet[object], /) -> bool: ...
14971549
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
14981550
def __ge__(self, value: AbstractSet[object], /) -> bool: ...

‎stdlib/types.pyi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ if sys.version_info >= (3, 15):
603603
def __len__(self) -> int: ...
604604
def __contains__(self, key: object, /) -> bool: ...
605605
def __reversed__(self) -> Iterator[str]: ...
606+
def __or__(self, other: dict[str, Any] | FrameLocalsProxyType, /) -> dict[str, Any]: ...
607+
# Will raise a NameError if invoked via |=
608+
def __ior__(self, other: dict[str, Any] | FrameLocalsProxyType, /) -> dict[str, Any]: ... # noqa: Y034
609+
def __ror__(self, other: dict[str, Any] | FrameLocalsProxyType, /) -> dict[str, Any]: ...
606610
def copy(self) -> dict[str, Any]: ...
607611
def pop(self, key: str, default: Any = ..., /) -> Any: ...
608612
def setdefault(self, key: str, default: Any = ..., /) -> Any: ...

‎stubs/tensorflow/tensorflow/io/__init__.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class RaggedFeature(NamedTuple):
9292

9393
dtype: DTypeLike
9494
value_key: str | None = None
95-
partitions: tuple[ # type: ignore[name-defined]
96-
RowSplits | RowLengths | RowStarts | RowLimits | ValueRowIds | UniformRowLength, ...
95+
partitions: tuple[
96+
RowSplits | RowLengths | RowStarts | RowLimits | ValueRowIds | UniformRowLength, ... # type: ignore[name-defined]
9797
] = ()
9898
row_splits_dtype: DTypeLike = ...
9999
validate: bool = False

0 commit comments

Comments
 (0)