mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[ty] Fix panic when trying to pull types for subscript expressions inside Callable
type expressions (#18534)
This commit is contained in:
parent
475a02b725
commit
aa3c312f5f
4 changed files with 61 additions and 17 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue