[Python-checkins] bpo-31564: Update typing documentation (GH-3696)

Mariatta webhook-mailer at python.org
Sat Sep 23 22:37:51 EDT 2017


https://github.com/python/cpython/commit/039b25d8fd21f8d5d9e3cb536402d952cf068dc1
commit: 039b25d8fd21f8d5d9e3cb536402d952cf068dc1
branch: master
author: topper-123 <terji78 at gmail.com>
committer: Mariatta <Mariatta at users.noreply.github.com>
date: 2017年09月23日T19:37:48-07:00
summary:
bpo-31564: Update typing documentation (GH-3696)
Mention that ``NewType`` can derive from another ``NewType``.
files:
M Doc/library/typing.rst
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 1e48fecdbf7..bd04f731a12 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::


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /