From 961b2ce5e5a0bb9cf271a698254b3a44336d165f Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Fri, 30 Jan 2026 18:43:00 +0100 Subject: [PATCH 1/2] Fix synced itertools.pyi --- ...001-Revert-Remove-redundant-inheritances-from-Iterator.patch | 2 +- mypy/typeshed/stdlib/itertools.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch index 0d64077e63d7..6194dc62cd36 100644 --- a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch +++ b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch @@ -289,7 +289,7 @@ index 8a924ad8b..5c2bf7f83 100644 if sys.version_info >= (3, 12): @disjoint_base - class batched(Generic[_T_co]): -+ class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]): ++ class batched(Iterator[_T_co], Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index 5c2bf7f83bba..4713d62cc346 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -341,7 +341,7 @@ if sys.version_info >= (3, 10): if sys.version_info >= (3, 12): @disjoint_base - class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]): + class batched(Iterator[_T_co], Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... From a22ddcf5f4adeb48078e1f0a1e23d65b7813df9a Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Fri, 30 Jan 2026 19:09:29 +0100 Subject: [PATCH 2/2] Add test --- test-data/unit/check-itertools.test | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test-data/unit/check-itertools.test diff --git a/test-data/unit/check-itertools.test b/test-data/unit/check-itertools.test new file mode 100644 index 000000000000..1c27b5515959 --- /dev/null +++ b/test-data/unit/check-itertools.test @@ -0,0 +1,47 @@ +[case testItertoolsBatched312] +# flags: --python-version 3.12 + +from itertools import batched + +b = batched([0], 1) +reveal_type(b) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(b.__next__()) # N: Revealed type is "builtins.tuple[builtins.int, ...]" + +reveal_type(batched([0, 0], 2)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(batched([0, 0, 0], 3)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(batched([0, 0, 0, 0], 4)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(batched([0, 0, 0, 0, 0], 5)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" + +reveal_type(batched([0], 2)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(batched([0], 2)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" + +def f() -> int: + return 3 + +reveal_type(batched([0, 0, 0], f())) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" + +[builtins fixtures/tuple.pyi] + +[case testItertoolsBatched313] +# flags: --python-version 3.13 + +from itertools import batched + +b = batched([0], 1, strict=True) +reveal_type(b) # N: Revealed type is "itertools.batched[tuple[builtins.int]]" +reveal_type(b.__next__()) # N: Revealed type is "tuple[builtins.int]" + +reveal_type(batched([0, 0], 2, strict=True)) # N: Revealed type is "itertools.batched[tuple[builtins.int, builtins.int]]" +reveal_type(batched([0, 0, 0], 3, strict=True)) # N: Revealed type is "itertools.batched[tuple[builtins.int, builtins.int, builtins.int]]" +reveal_type(batched([0, 0, 0, 0], 4, strict=True)) # N: Revealed type is "itertools.batched[tuple[builtins.int, builtins.int, builtins.int, builtins.int]]" +reveal_type(batched([0, 0, 0, 0, 0], 5, strict=True)) # N: Revealed type is "itertools.batched[tuple[builtins.int, builtins.int, builtins.int, builtins.int, builtins.int]]" + +reveal_type(batched([0], 2),) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" +reveal_type(batched([0], 2, strict=False)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" + +def f() -> int: + return 3 + +reveal_type(batched([0, 0, 0], f(), strict=True)) # N: Revealed type is "itertools.batched[builtins.tuple[builtins.int, ...]]" + +[builtins fixtures/tuple.pyi]