Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NewType documentation is incorrect #11620

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
AlexWaygood opened this issue Nov 25, 2021 · 2 comments · Fixed by #11621
Closed

NewType documentation is incorrect #11620

AlexWaygood opened this issue Nov 25, 2021 · 2 comments · Fixed by #11621

Comments

@AlexWaygood
Copy link
Member

The documentation for NewType at https://mypy.readthedocs.io/en/stable/more_types.html#newtypes states:

...the typing module provides a helper function NewType that creates simple unique types with almost zero runtime overhead.

However, as the cpython documentation for NewType` states:

Changed in version 3.10: NewType is now a class rather than a function. There is some additional runtime cost when calling NewType over a regular function. However, this cost will be reduced in 3.11.0.

In Python >=3.10, NewType is a class rather than a function, meaning the mypy documentation is now incorrect.

I'm not immediately sure how it could be rewritten in a more accurate way that is still concise, however.

@JelleZijlstra
Copy link
Member

We can just replace "function" with "object". The overhead is still tiny, and it doesn't matter to readers of the mypy documentation exactly how NewType is implemented.

AlexWaygood added a commit to AlexWaygood/mypy that referenced this issue Nov 26, 2021
NewType is a class in Python >=3.10, meaning the mypy documentation is no longer accurate.

Closes python#11620
@AlexWaygood
Copy link
Member Author

We can just replace "function" with "object". The overhead is still tiny, and it doesn't matter to readers of the mypy documentation exactly how NewType is implemented.

Makes sense, thanks!

hauntsaninja pushed a commit that referenced this issue Nov 26, 2021
NewType is a class in Python >=3.10, meaning the mypy documentation is no longer accurate.

Closes #11620
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
NewType is a class in Python >=3.10, meaning the mypy documentation is no longer accurate.

Closes python#11620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants