-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-41923: PEP 613: Add TypeAlias to typing module #22532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gvanrossum
merged 4 commits into
python:master
from
east825:bpo-41923_PEP-613_typing.TypeAlias
Oct 7, 2020
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c15b706
bpo-41923: PEP 613: Add TypeAlias to typing module
east825 b5a088d
Merge branch 'master' of github.com:python/cpython into bpo-41923_PEP…
east825 c49533f
Draft the bare-bones documentation for TypeAlias
east825 1c2fecf
Fix PEPNNN heading titles
gvanrossum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,10 +82,50 @@ New Features | |||||||||
| * :pep:`618`: The :func:`zip` function now has an optional ``strict`` flag, used | ||||||||||
| to require that all the iterables have an equal length. | ||||||||||
|
|
||||||||||
| * :pep:`613`: The :mod:`typing` module now has a special annotation | ||||||||||
| :class:`TypeAlias` to explicitly declare :pep:`484`-compliant type aliases, | ||||||||||
| better differentiating them from regular assignments. | ||||||||||
| PEP613: TypeAlias Annotation | ||||||||||
| ---------------------------- | ||||||||||
|
|
||||||||||
| :pep:`484` introduced the concept of type aliases, only requiring them to be | ||||||||||
| top-level unannotated assignments. This simplicity sometimes made it difficult | ||||||||||
| for type checkers to distinguish between type aliases and ordinary assignments, | ||||||||||
| especially when forward references or invalid types were involved. Compare:: | ||||||||||
|
|
||||||||||
| StrCache = 'Cache[str]' # a type alias | ||||||||||
| LOG_PREFIX = 'LOG[DEBUG]' # a module constant | ||||||||||
|
|
||||||||||
| Now the :mod:`typing` module has a special annotation :data:`TypeAlias` to | ||||||||||
| declare type aliases more explicitly:: | ||||||||||
|
|
||||||||||
| StrCache: TypeAlias = 'Cache[str]' # a type alias | ||||||||||
| LOG_PREFIX = 'LOG[DEBUG]' # a module constant | ||||||||||
|
|
||||||||||
| See :pep:`613` for more details. | ||||||||||
|
|
||||||||||
| (Contributed by Mikhail Golubev in :issue:`41923`.) | ||||||||||
|
|
||||||||||
| PEP604: New Type Operator | ||||||||||
| ------------------------- | ||||||||||
|
||||||||||
| PEP604: New Type Operator | |
| ------------------------- | |
| PEP 604: New Type Union Operator | |
| -------------------------------- |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| Now, type hints can be written in a more succinct manner:: | |
| Type hints can now be written in a more succinct manner:: |
2 changes: 1 addition & 1 deletion
2
Misc/NEWS.d/next/Library/2020-10-03-23-14-50.bpo-41923.Buonw9.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Implement :pep:`613`, introducing :class:`typing.TypeAlias` annotation. | ||
| Implement :pep:`613`, introducing :data:`typing.TypeAlias` annotation. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.