Skip to content

NewType documentation is incorrect  #11620

Closed

Description

@AlexWaygood

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.

Activity

  1. JelleZijlstra commented on Nov 26, 2021

    @JelleZijlstra
    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.

  2. added a commit that references this issue on Nov 26, 2021
    dfb1bf6
  3. AlexWaygood commented on Nov 26, 2021

    @AlexWaygood
    MemberAuthor

    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!

  4. added a commit that references this issue on Nov 26, 2021
    eea4c76
  5. added a commit that references this issue on Jan 20, 2022
    d013734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions