Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/itertools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
Expand Down
47 changes: 47 additions & 0 deletions test-data/unit/check-itertools.test
Original file line number Diff line number Diff line change
@@ -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]