[ty] Fix panic when trying to pull types for subscript expressions inside Callable type expressions (#18534)

This commit is contained in:
Alex Waygood 2025-06-09 11:26:10 +01:00 committed by GitHub
parent 475a02b725
commit aa3c312f5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 61 additions and 17 deletions

View file

@ -252,6 +252,31 @@ def _(c: Callable[[Concatenate[int, str, ...], int], int]):
reveal_type(c) # revealed: (...) -> int
```
Other type expressions can be nested inside `Concatenate`:
```py
def _(c: Callable[[Concatenate[int | str, type[str], ...], int], int]):
# TODO: Should reveal the correct signature
reveal_type(c) # revealed: (...) -> int
```
But providing fewer than 2 arguments to `Concatenate` is an error:
```py
# fmt: off
def _(
c: Callable[Concatenate[int], int], # error: [invalid-type-form] "Special form `typing.Concatenate` expected at least 2 parameters but got 1"
d: Callable[Concatenate[(int,)], int], # error: [invalid-type-form] "Special form `typing.Concatenate` expected at least 2 parameters but got 1"
e: Callable[Concatenate[()], int] # error: [invalid-type-form] "Special form `typing.Concatenate` expected at least 2 parameters but got 0"
):
reveal_type(c) # revealed: (...) -> int
reveal_type(d) # revealed: (...) -> int
reveal_type(e) # revealed: (...) -> int
# fmt: on
```
## Using `typing.ParamSpec`
```toml