-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Make types.NoneType
actually the type of None
, instead of just some unrelated class
#6125
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
Conversation
7fbf66a
to
e708c16
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I don't think this change should be made. It will break assumptions in mypy and pyright (and probably other type checkers) about how a: Hashable = None What problem is this PR attempting to solve? If the intent is to enable users to use |
Well I would think that if the type in What about something more like: class _NoneType:
def __bool__(self) -> Literal[False]: ...
def __hash__(self) -> int: ...
None: _NoneType types.pyi: from builtins import _NoneType
NoneType = _NoneType |
I don't think that modifications solves anything, and it will break even more than the previous PR.
That's not consistent with my understanding. If you're importing I think this PR is attempting to solve a non-problem. Let's keep things the way they are. If you have a need to refer to the type of None, just use |
I guess I just want it for completeness sake. It would actually be better then if the type checkers disallowed the usage of |
What a mess, I would prefer if def foo(n: NoneType):
isinstance(n, NoneType)
# consistent? whaaa? Fair enough though if you guys think this not a good one. |
@erictraut @JelleZijlstra What about typing |
The classes defined in I saw that you filed a feature request in the mypy issue tracker to issue an error when I think the best solution here is to improve the documentation to make it clear that most Python code should not import from the |
I mean used as a type annotation, I can't think of any possible usage. |
python/mypy#11285 (comment) |
They're used in tools that need to inspect Python internals. For example, the mypy source code needs to use these types. In these contexts, they're legitimate to use within type annotations. |
I understand that there are always edge cases, and disabling those warnings with a type comment would be the way to go IMO. With the special case of |
We lose the types from
NoneType.__bool__()
but I think it's worth it.