Description
Some AST nodes are always invalid in type expressions; we should emit an invalid-type-form
diagnostic in red-knot if we see one of these in a type expression. This applies to all of these branches:
ruff/crates/red_knot_python_semantic/src/types/infer.rs
Lines 6150 to 6233 in 7ca5f13
Similarly, an ellipsis literal is only valid in very specific contexts in type expressions: as part of a Callable
type expression (e.g. Callable[..., int]
or as part of a tuple
-subscript type expression (e.g. tuple[int, ...]
. We should never call infer_type_expression_no_store
with an ellipsis literal node if we're visiting a sub-expression in either of those type expressions. So we should also be emitting a diagnostic if we hit this branch:
ruff/crates/red_knot_python_semantic/src/types/infer.rs
Lines 6070 to 6074 in 7ca5f13
This would be a good contributor task. The changes required will be very similar to the ones done in #16765. @MatthewMckee4, you might be interested in taking this one on, possibly? :-)