[ty] Understand homogeneous tuple annotations (#17998)

This commit is contained in:
Alex Waygood 2025-05-12 22:02:25 -04:00 committed by GitHub
parent f301931159
commit 55df9271ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 196 additions and 104 deletions

View file

@ -317,8 +317,7 @@ reveal_type(A() + b"foo") # revealed: A
reveal_type(b"foo" + A()) # revealed: bytes
reveal_type(A() + ()) # revealed: A
# TODO this should be `A`, since `tuple.__add__` doesn't support `A` instances
reveal_type(() + A()) # revealed: @Todo(full tuple[...] support)
reveal_type(() + A()) # revealed: A
literal_string_instance = "foo" * 1_000_000_000
# the test is not testing what it's meant to be testing if this isn't a `LiteralString`:

View file

@ -17,6 +17,7 @@ def _(x: tuple[int, str], y: tuple[None, tuple[int]]):
```py
def _(x: tuple[int, ...], y: tuple[str, ...]):
reveal_type(x + y) # revealed: @Todo(full tuple[...] support)
reveal_type(x + (1, 2)) # revealed: @Todo(full tuple[...] support)
# TODO: should be `tuple[int | str, ...]`
reveal_type(x + y) # revealed: tuple[int | Unknown, ...]
reveal_type(x + (1, 2)) # revealed: tuple[int, ...]
```