You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
gvanrossum commentedon Jan 24, 2018
Also e.g.
ilevkivskyi commentedon Jan 24, 2018
This case is actually quite important, especially while #3494 (document variables vs aliases) is not fixed.
Remove RawLiteralType synthetic type
ilevkivskyi commentedon Feb 4, 2019
A rare case where adding "Invalid type" would be actually helpful is the error message for using subscriptable metaclasses in type context, see #6313.
ilevkivskyi commentedon Feb 11, 2019
A similar example where we should give a better error message is (recently closed) #2477
ilevkivskyi commentedon May 19, 2019
One more example is cast targets, see #6862
[-]Better error messge for "Invalid type"[/-][+]Better error message for "Invalid type"[/+]Add more details for "Invalid type" errors (#7166)