Skip to content

Failure solving iterability of a class with a generic __iter__ method #3598

@hamdanal

Description

@hamdanal

Summary

This might be a duplicate of one of the issues related to the constraint solver but couldn't tell which.

from collections.abc import Iterable, Iterator

class Unpacker[T: Iterable]:
    def __iter__[S](self: "Unpacker[Iterable[S]]") -> Iterator[S]: ...

def integers() -> Unpacker[Iterable[int]]: ...

# OK
reveal_type(tuple(integers()))  # Revealed type: `tuple[int, ...]`
for x in integers():
    reveal_type(x)  # Revealed type: `int
# NOT OK
reveal_type(list(integers()))  # Revealed type: `list[Unknown]`
                               # Expected: `list[int]`
reveal_type(iter(integers()))  # Revealed type: `Unknown`
                               # Expected: `Iterator[int]`

Playground

Version

ty 0.0.40

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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