summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-09-24 02:46:24 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-09-24 02:46:24 (GMT)
commit018e6b9f696311a65f47f33ea04b7baef3f3664f (patch)
tree05925dd82a489dacfcb6ac3b3c5c65f1e5193ed3 /Doc/library
parent7e32cee1a68a489c4f2e916ac7003004b51887de (diff)
downloadcpython-018e6b9f696311a65f47f33ea04b7baef3f3664f.zip
cpython-018e6b9f696311a65f47f33ea04b7baef3f3664f.tar.gz
cpython-018e6b9f696311a65f47f33ea04b7baef3f3664f.tar.bz2
bpo-31564: Update typing documentation (GH-3696) (GH-3715)
Mention that ``NewType`` can derive from another ``NewType``. (cherry picked from commit 039b25d8fd21f8d5d9e3cb536402d952cf068dc1)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/typing.rst12
1 files changed, 9 insertions, 3 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 1e48fec..bd04f73 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -111,8 +111,7 @@ More precisely, the expression ``some_value is Derived(some_value)`` is always
true at runtime.
This also means that it is not possible to create a subtype of ``Derived``
-since it is an identity function at runtime, not an actual type. Similarly, it
-is not possible to create another :func:`NewType` based on a ``Derived`` type::
+since it is an identity function at runtime, not an actual type::
from typing import NewType
@@ -121,9 +120,16 @@ is not possible to create another :func:`NewType` based on a ``Derived`` type::
# Fails at runtime and does not typecheck
class AdminUserId(UserId): pass
- # Also does not typecheck
+However, it is possible to create a :func:`NewType` based on a 'derived' ``NewType``::
+
+ from typing import NewType
+
+ UserId = NewType('UserId', int)
+
ProUserId = NewType('ProUserId', UserId)
+and typechecking for ``ProUserId`` will work as expected.
+
See :pep:`484` for more details.
.. note::