ty icon indicating copy to clipboard operation
ty copied to clipboard

Unable to infer zip type

Open phistep opened this issue 1 week ago • 1 comments

Question

class Foo: ...


d = dict(a=Foo())

p = list(d.items())
pp = zip(p, p, strict=True)
Image

https://play.ty.dev/7c1cf9a0-a632-41bc-a7ac-552c87e34308

I would expect the type checker to be able to infer the type of pp fully, as it knows the type of p. what would the correct type be here?

zip has a signature of

def __new__(
    iter1: Iterable[_T1@__new__],
    iter2: Iterable[_T2@__new__],
    *,
    /,
    strict: bool = False
) -> zip[tuple[_T1@__new__, _T2@__new__]]

so my guess would be

zip[
    tuple[
        tuple[str, Foo]
        tuple[str, Foo]
    ]
]

Version

~/Library/Application Support/Zed/languages/ty/ty-0.0.7/ty-aarch64-apple-darwin/ty

Bundled with Zed 0.217.3+stable.105.80433cb239e868271457ac376673a5f75bc4adb1

phistep avatar Dec 29 '25 02:12 phistep

I might be wrong on this (not a typing expert) but I think this might be due to ty's lack of support for generic protocols (Iterable is a generic protocol).

See https://github.com/astral-sh/ty/issues/1714

MichaReiser avatar Dec 29 '25 10:12 MichaReiser

Yes, this looks like #1714

AlexWaygood avatar Dec 29 '25 14:12 AlexWaygood