Skip to content

Values with the type annotation of type aren't valid as types #11286

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

Closed
KotlinIsland opened this issue Oct 7, 2021 · 4 comments
Closed

Values with the type annotation of type aren't valid as types #11286

KotlinIsland opened this issue Oct 7, 2021 · 4 comments
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

NoneType1: type[None] = type(None)
NoneType2 = type(None)

none1: NoneType1 = None  # error: Variable "NoneType1" is not valid as a type
none2: NoneType2 = None  # no error

Pyright handles this correctly.

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Oct 7, 2021
@erictraut
Copy link

I think this is a problem in pyright rather than mypy. In your example, NoneType1 and NoneType2 are variables and not valid type aliases, so they shouldn't be allowed as type annotations. Arguably, uses of both NoneType1 and NoneType2 within an annotation should result in an error.

If you want to define a type alias that represents the type of the None object, it should be defined like this:

NoneType1 = type[None]

none1: NoneType1 = type(None)

This works fine in mypy (and in pyright).

@KotlinIsland
Copy link
Contributor Author

What I really want is something that can be used as a type alias for the type of None, and is also the type of None(NoneType).

@KotlinIsland
Copy link
Contributor Author

Mypy should report that using NoneType sucks because of this typing mess. I'll raise that instead.

@KotlinIsland
Copy link
Contributor Author

Closed in favor of #11288.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants