Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,75 @@ def _(c: Callable[[...], int]):
reveal_type(c) # revealed: (...) -> int
```

The invalid parameter list also offers an autofix that replaces the list with an ellipsis.

```py
def fixable(callback: Callable[[...], int]): ... # snapshot: invalid-type-form
```

```snapshot
error[invalid-type-form]: `[...]` is not a valid parameter list for `Callable`
--> src/mdtest_snippet.py:17:32
|
17 | def fixable(callback: Callable[[...], int]): ... # snapshot: invalid-type-form
| ^^^^^ Did you mean `Callable[..., int]`?
info: See the following page for a reference on valid type expressions:
info: https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions
help: Replace `[...]` with `...`
|
16 | reveal_type(c) # revealed: (...) -> int
- def fixable(callback: Callable[[...], int]): ... # snapshot: invalid-type-form
17 + def fixable(callback: Callable[..., int]): ... # snapshot: invalid-type-form
18 | def with_comments(
|
note: This is an unsafe fix and may change runtime behavior
```

A multiline parameter list can contain comments, so its brackets are not removed automatically.

```py
def with_comments(
callback: Callable[
[ # snapshot: invalid-type-form
# The callable accepts arbitrary arguments.
..., # The parameter description remains documented.
],
int,
],
): ...
```

```snapshot
error[invalid-type-form]: `[...]` is not a valid parameter list for `Callable`
--> src/mdtest_snippet.py:20:9
|
20 | / [ # snapshot: invalid-type-form
21 | | # The callable accepts arbitrary arguments.
22 | | ..., # The parameter description remains documented.
23 | | ],
| |_________^ Did you mean `Callable[..., int]`?
info: See the following page for a reference on valid type expressions:
info: https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions
```

A quoted callable annotation still receives the diagnostic, but its parsed source range cannot be
rewritten directly.

```py
# snapshot: invalid-type-form
def quoted(callback: "Callable[[...], int]"): ...
```

```snapshot
error[invalid-type-form]: `[...]` is not a valid parameter list for `Callable`
--> src/mdtest_snippet.py:28:32
|
28 | def quoted(callback: "Callable[[...], int]"): ...
| ^^^^^ Did you mean `Callable[..., int]`?
info: See the following page for a reference on valid type expressions:
info: https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions
```

```py
# error: [invalid-type-form] "`...` is not allowed in this context in a parameter annotation"
def _(c: Callable[[int, ...], int]):
Expand Down
Loading
Loading