File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,7 @@ More precisely, the expression ``some_value is Derived(some_value)`` is always
111
111
true at runtime.
112
112
113
113
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::
116
115
117
116
from typing import NewType
118
117
@@ -121,9 +120,16 @@ is not possible to create another :func:`NewType` based on a ``Derived`` type::
121
120
# Fails at runtime and does not typecheck
122
121
class AdminUserId(UserId): pass
123
122
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
+
125
129
ProUserId = NewType('ProUserId', UserId)
126
130
131
+ and typechecking for ``ProUserId `` will work as expected.
132
+
127
133
See :pep: `484 ` for more details.
128
134
129
135
.. note ::
You can’t perform that action at this time.
0 commit comments