ty
ty copied to clipboard
Inconsistent type inference for `tuple[int, ...]` when using `type` and `TypeAlias`
Summary
Wasn't sure how to describe this exactly but here's a small reproducer. Notice that foo_slice is either inferred to be tuple[int, int] or tuple[int, ...] depending on how Version is defined:
Using TypeAlias
Version: TypeAlias = tuple[int, int, int]
def foo() -> Version:
return (1, 2, 3)
# Inferred as tuple[int, int]
foo_slice = foo()[:2]
Using type keyword
type Version = tuple[int, int, int]
def foo() -> Version:
return (1, 2, 3)
# Inferred as tuple[int, ...]
foo_slice = foo()[:2]
I'd expect both to behave the same, ruff even recommends to use the latter..
playground link: https://play.ty.dev/d8cdb949-9e7e-48e5-8866-f41eac402931
Version
ty 0.0.2
Thanks for the report, definitely a bug.