Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
039b25d8
Commit
039b25d8
authored
Sep 24, 2017
by
topper-123
Committed by
Mariatta
Sep 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31564: Update typing documentation (GH-3696)
Mention that ``NewType`` can derive from another ``NewType``.
parent
d6238a76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
Doc/library/typing.rst
Doc/library/typing.rst
+9
-3
No files found.
Doc/library/typing.rst
View file @
039b25d8
...
...
@@ -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::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment