Skip to content

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

Closed
@dhruvmanila

Description

@dhruvmanila

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcometyMulti-file analysis & type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions