-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-42737: Mention PEP 563 in doc for annotated assignment #25511
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,15 +335,20 @@ statement, of a variable or attribute annotation and an optional assignment stat | |
| The difference from normal :ref:`assignment` is that only single target is allowed. | ||
|
|
||
| For simple names as assignment targets, if in class or module scope, | ||
| the annotations are evaluated and stored in a special class or module | ||
| the annotations are available in a special class or module | ||
| attribute :attr:`__annotations__` | ||
| that is a dictionary mapping from variable names (mangled if private) to | ||
| evaluated annotations. This attribute is writable and is automatically | ||
| that is a dictionary mapping from variable names (mangled if private) to the | ||
| annotations. This attribute is writable and is automatically | ||
| created at the start of class or module body execution, if annotations | ||
| are found statically. | ||
| are found statically. If the ``annotations`` import from :mod:`__future__` is used | ||
| (i.e. :pep:`563` is enabled), the annotations are stored as string values in | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we should link to the documentation for the |
||
| :attr:`__annotations__` at runtime which enables postponed evaluation. Otherwise, | ||
| they are eagerly evaluated at runtime in the corresponding scope and then stored into | ||
| :attr:`__annotations__`. | ||
|
|
||
| For expressions as assignment targets, the annotations are evaluated if | ||
| in class or module scope, but not stored. | ||
| in class or module scope (regardless of whether :pep:`563` is enabled), but not | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really? That seems like a bug. |
||
| stored. | ||
|
|
||
| If a name is annotated in a function scope, then this name is local for | ||
| that scope. Annotations are never evaluated and stored in function scopes. | ||
|
|
@@ -366,6 +371,10 @@ target, then the interpreter evaluates the target except for the last | |
| syntax for type annotations that can be used in static analysis tools and | ||
| IDEs. | ||
|
|
||
| :pep:`563` - Postponed Evaluation of Annotations | ||
| Support for forward references within annotations by preserving | ||
| annotations in a string form at runtime instead of eager evaluation. | ||
|
|
||
| .. versionchanged:: 3.8 | ||
| Now annotated assignments allow same expressions in the right hand side as | ||
| the regular assignments. Previously, some expressions (like un-parenthesized | ||
|
|
||
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.
Reads better without the article