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
{{ message }}
Repository navigation
Values with the type annotation of type aren't valid as types #11286
NoneType1: type[None] =type(None)
NoneType2=type(None)
none1: NoneType1=None# error: Variable "NoneType1" is not valid as a typenone2: NoneType2=None# no error
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:
Activity
erictraut commentedon Oct 7, 2021
I think this is a problem in pyright rather than mypy. In your example,
NoneType1andNoneType2are variables and not valid type aliases, so they shouldn't be allowed as type annotations. Arguably, uses of bothNoneType1andNoneType2within an annotation should result in an error.If you want to define a type alias that represents the type of the
Noneobject, it should be defined like this:This works fine in mypy (and in pyright).
KotlinIsland commentedon Oct 7, 2021
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 commentedon Oct 7, 2021
Mypy should report that using
NoneTypesucks because of this typing mess. I'll raise that instead.KotlinIsland commentedon Oct 7, 2021
Closed in favor of #11288.