Skip to content

itertools.groupby turns [A] | [B] into [A | B] #16018

Description

@shenriotpro

Hi, hope this snippet helps, runs fine, but ty complains
Expected Iterator[str] | Iterator[int], found Iterator[str | int]

from itertools import groupby
from typing import Sequence, Iterator


def group(items: Sequence[str] | Sequence[int]):
    for key, group in groupby(items):
        f(group)
    

def f(items: Iterator[str] | Iterator[int]):
    print(list(items))


group(["a", "b", "c"])
group([1, 2, 3])

Metadata

Metadata

Assignees

No one assigned

    Labels

    reason: inexpressibleClosed, because this can't be expressed within the current type system

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions