Skip to content

Commit eea4c76

Browse files
authored
Correct documentation for NewType (#11621)
NewType is a class in Python >=3.10, meaning the mypy documentation is no longer accurate. Closes #11620
1 parent 1bcfc04 commit eea4c76

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

docs/source/more_types.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ certain values from base class instances. Example:
8484
...
8585
8686
However, this approach introduces some runtime overhead. To avoid this, the typing
87-
module provides a helper function :py:func:`NewType <typing.NewType>` that creates simple unique types with
87+
module provides a helper object :py:func:`NewType <typing.NewType>` that creates simple unique types with
8888
almost zero runtime overhead. Mypy will treat the statement
8989
``Derived = NewType('Derived', Base)`` as being roughly equivalent to the following
9090
definition:
@@ -95,7 +95,7 @@ definition:
9595
def __init__(self, _x: Base) -> None:
9696
...
9797
98-
However, at runtime, ``NewType('Derived', Base)`` will return a dummy function that
98+
However, at runtime, ``NewType('Derived', Base)`` will return a dummy callable that
9999
simply returns its argument:
100100

101101
.. code-block:: python
@@ -127,7 +127,7 @@ containing the name of the new type and must equal the name of the variable to w
127127
type is assigned. The second argument must be a properly subclassable class, i.e.,
128128
not a type construct like :py:data:`~typing.Union`, etc.
129129

130-
The function returned by :py:func:`NewType <typing.NewType>` accepts only one argument; this is equivalent to
130+
The callable returned by :py:func:`NewType <typing.NewType>` accepts only one argument; this is equivalent to
131131
supporting only one constructor accepting an instance of the base class (see above).
132132
Example:
133133

@@ -148,8 +148,7 @@ Example:
148148
tcp_packet = TcpPacketId(127, 0) # Fails in type checker and at runtime
149149
150150
You cannot use :py:func:`isinstance` or :py:func:`issubclass` on the object returned by
151-
:py:func:`~typing.NewType`, because function objects don't support these operations. You cannot
152-
create subclasses of these objects either.
151+
:py:func:`~typing.NewType`, nor can you subclass an object returned by :py:func:`~typing.NewType`.
153152

154153
.. note::
155154

0 commit comments

Comments
 (0)