Skip to content

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

@tomasr8

Description

@tomasr8

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions