Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-119180: More documentation for PEP 649/749#133552
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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,7 +82,7 @@ and improvements in user-friendliness and correctness. | ||
| .. PEP-sized items next. | ||
| * :ref:`PEP 649: deferred evaluation of annotations <whatsnew314-pep649>` | ||
| * :ref:`PEP 649 and 749: deferred evaluation of annotations <whatsnew314-pep649>` | ||
| * :ref:`PEP 741: Python Configuration C API <whatsnew314-pep741>` | ||
| * :ref:`PEP 750: Template strings <whatsnew314-pep750>` | ||
| * :ref:`PEP 758: Allow except and except* expressions without parentheses <whatsnew314-pep758>` | ||
| @@ -361,18 +361,19 @@ Check :pep:`758` for more details. | ||
| .. _whatsnew314-pep649: | ||
| PEP 649: deferred evaluation of annotations | ||
| ------------------------------------------- | ||
| PEP 649 and 749: deferred evaluation of annotations | ||
| --------------------------------------------------- | ||
| The :term:`annotations <annotation>` on functions, classes, and modules are no | ||
| longer evaluated eagerly. Instead, annotations are stored in special-purpose | ||
| :term:`annotate functions <annotate function>` and evaluated only when | ||
| necessary. This is specified in :pep:`649` and :pep:`749`. | ||
| necessary (except if ``from __future__ import annotations`` is used). | ||
| This is specified in :pep:`649` and :pep:`749`. | ||
| This change is designed to make annotations in Python more performant and more | ||
| usable in most circumstances. The runtime cost for defining annotations is | ||
| minimized, but it remains possible to introspect annotations at runtime. | ||
| It is usually no longer necessary to enclose annotations in strings if they | ||
| It is no longer necessary to enclose annotations in strings if they | ||
| contain forward references. | ||
| The new :mod:`annotationlib` module provides tools for inspecting deferred | ||
| @@ -408,7 +409,8 @@ writing annotations the same way you did with previous versions of Python. | ||
| You will likely be able to remove quoted strings in annotations, which are frequently | ||
| used for forward references. Similarly, if you use ``from __future__ import annotations`` | ||
| to avoid having to write strings in annotations, you may well be able to | ||
| remove that import. However, if you rely on third-party libraries that read annotations, | ||
| remove that import once you support only Python 3.14 and newer. | ||
| However, if you rely on third-party libraries that read annotations, | ||
| those libraries may need changes to support unquoted annotations before they | ||
| work as expected. | ||
| @@ -421,6 +423,11 @@ annotations. For example, you may want to use :func:`annotationlib.get_annotatio | ||
| with the :attr:`~annotationlib.Format.FORWARDREF` format, as the :mod:`dataclasses` | ||
| module now does. | ||
| The external :pypi:`typing_extensions` package provides partial backports of some of the | ||
| functionality of the :mod:`annotationlib` module, such as the :class:`~annotationlib.Format` | ||
| enum and the :func:`~annotationlib.get_annotations` function. These can be used to | ||
| write cross-version code that takes advantage of the new behavior in Python 3.14. | ||
| Related changes | ||
| ^^^^^^^^^^^^^^^ | ||
| @@ -432,6 +439,10 @@ functions in the standard library, there are many ways in which your code may | ||
| not work in Python 3.14. To safeguard your code against future changes, | ||
| use only the documented functionality of the :mod:`annotationlib` module. | ||
| In particular, do not read annotations directly from the namespace dictionary | ||
| attribute of type objects. Use :func:`annotationlib.get_annotate_from_class_namespace` | ||
| during class construction and :func:`annotationlib.get_annotations` afterwards. | ||
| ``from __future__ import annotations`` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| @@ -443,8 +454,10 @@ Python without deferred evaluation of annotations, reaches its end of life in 20 | ||
| In Python 3.14, the behavior of code using ``from __future__ import annotations`` | ||
| is unchanged. | ||
| (Contributed by Jelle Zijlstra in :gh:`119180`; :pep:`649` was written by Larry Hastings.) | ||
JelleZijlstra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .. seealso:: | ||
| :pep:`649`. | ||
| :pep:`649` and :pep:`749`. | ||
| Improved error messages | ||
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.