ty icon indicating copy to clipboard operation
ty copied to clipboard

Inconsistent type inference for `tuple[int, ...]` when using `type` and `TypeAlias`

Open tomasr8 opened this issue 2 months ago • 1 comments

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

tomasr8 avatar Dec 17 '25 14:12 tomasr8

Thanks for the report, definitely a bug.

carljm avatar Dec 17 '25 22:12 carljm