8000 bpo-31564: Update typing documentation (GH-3696) (GH-3715) · python/cpython@018e6b9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 018e6b9

Browse files
miss-islingtonMariatta
authored andcommitted
bpo-31564: Update typing documentation (GH-3696) (GH-3715)
Mention that ``NewType`` can derive from another ``NewType``. (cherry picked from commit 039b25d)
1 parent 7e32cee commit 018e6b9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Doc/library/typing.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ More precisely, the expression ``some_value is Derived(some_value)`` is always
111111
true at runtime.
112112

113113
This also means that it is not possible to create a subtype of ``Derived``
114-
since it is an identity function at runtime, not an actual type. Similarly, it
115-
is not possible to create another :func:`NewType` based on a ``Derived`` type::
114+
since it is an identity function at runtime, not an actual type::
116115

117116
from typing import NewType
118117

@@ -121,9 +120,16 @@ is not possible to create another :func:`NewType` based on a ``Derived`` type::
121120
# Fails at runtime and does not typecheck
122121
class AdminUserId(UserId): pass
123122

124-
# Also does not typecheck
123+
However, it is possible to create a :func:`NewType` based on a 'derived' ``NewType``::
124+
125+
from typing import NewType
126+
127+
UserId = NewType('UserId', int)
128+
125129
ProUserId = NewType('ProUserId', UserId)
126130

131+
and typechecking for ``ProUserId`` will work as expected.
132+
127133
See :pep:`484` for more details.
128134

129135
.. note::

0 commit comments

Comments
 (0)
0