Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Raise "invalid type expression" error for literal types #16532

Closed
dhruvmanila opened this issue Mar 6, 2025 · 0 comments · Fixed by #16765
Closed

[red-knot] Raise "invalid type expression" error for literal types #16532

dhruvmanila opened this issue Mar 6, 2025 · 0 comments · Fixed by #16765
Labels
help wanted Contributions especially welcome red-knot Multi-file analysis & type inference

Comments

@dhruvmanila
Copy link
Member

dhruvmanila commented Mar 6, 2025

The task is to raise a invalid-type-form error that states "Invalid type expression" for the following three literal types:

// Other literals do not have meaningful values in the annotation expression context.
// However, we will we want to handle these differently when working with special forms,
// since (e.g.) `123` is not valid in an annotation expression but `Literal[123]` is.
ast::Expr::BytesLiteral(_literal) => todo_type!("bytes literal in type expression"),
ast::Expr::NumberLiteral(_literal) => todo_type!("number literal in type expression"),
ast::Expr::BooleanLiteral(_literal) => todo_type!("boolean literal in type expression"),

The reason is that those literal types are handled appropriately in the relevant context like typing.Literal, typing.Annotated.

This will also require fixing / updating the tests w.r.t. this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions especially welcome red-knot Multi-file analysis & type inference
Projects
None yet
1 participant