Skip to content
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

Reject types.NoneType and suggest using None instead #13139

Closed
JukkaL opened this issue Jul 16, 2022 · 2 comments
Closed

Reject types.NoneType and suggest using None instead #13139

JukkaL opened this issue Jul 16, 2022 · 2 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 16, 2022

types.NoneType is the same as type(None) at runtime, and mypy doesn't recognize this. However, we don't want multiple was of representing None in type annotations, so we should generate an error if types.NoneType is used in a type annotation.

Hints:

  • Fix this in mypy.typeanal
  • Currently types.NoneType is treated as an mypy.types.Instance type but None is mapped to mypy.types.NoneType
  • If we'd create an Instance with fullname equal to types.NoneType, generate an error

Example illustrating the problem:

from types import NoneType

def f(x: NoneType) -> None:
    pass

f(None)   # Incompatible type None, expected NoneType
@AlexWaygood
Copy link
Member

This is a similar issue to #11288 :)

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 16, 2022

Closed as dupe of #11288.

@JukkaL JukkaL closed this as completed Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants