@@ -84,7 +84,7 @@ certain values from base class instances. Example:
84
84
...
85
85
86
86
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
88
88
almost zero runtime overhead. Mypy will treat the statement
89
89
``Derived = NewType('Derived', Base) `` as being roughly equivalent to the following
90
90
definition:
@@ -95,7 +95,7 @@ definition:
95
95
def __init__ (self , _x : Base) -> None :
96
96
...
97
97
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
99
99
simply returns its argument:
100
100
101
101
.. code-block :: python
@@ -127,7 +127,7 @@ containing the name of the new type and must equal the name of the variable to w
127
127
type is assigned. The second argument must be a properly subclassable class, i.e.,
128
128
not a type construct like :py:data: `~typing.Union `, etc.
129
129
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
131
131
supporting only one constructor accepting an instance of the base class (see above).
132
132
Example:
133
133
@@ -148,8 +148,7 @@ Example:
148
148
tcp_packet = TcpPacketId(127 , 0 ) # Fails in type checker and at runtime
149
149
150
150
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 `.
153
152
154
153
.. note ::
155
154
0 commit comments