Skip to content

Better error message for "Invalid type" #4030

Description

@ilevkivskyi

There several situations where a quite terse error message is given: Invalid type "__main__.T" -- this could be an attempt to use a variable as a type, attempt to use function as a type, unsupported forward reference, maybe some other. I propose to make this error message more specific, or add a note:

error: Invalid type "__main__.f"
note: Functions can't be used as a type

and

error: Invalid type "__main__.Alias"
note: Variables can't be used as a type

The second can be also useful if someone accidentally created a variable instead of an alias. In this case we can even append a link to docs, if we detect that variable has type Type[...].

Another similar terse error message is Invalid base class. We can say which base is invalid, this will be useful in case of multiple bases on the same line, and maybe also add a note in some cases explaining why it is invalid, like note: Union types can't be subclassed, so that it is clear what went wrong.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions