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
bpo-42737: Mention PEP 563 in doc for annotated assignment #25511
base: main
Are you sure you want to change the base?
Conversation
Please hold this PR until #23952 is resolved first. |
@gousaiyang could you please update the PR with the new changes (if necessary) |
I think it might be better to merge this PR and create a separate one to document the changes in #23952, since the changes in this PR applies to (and thus can be backported) all Python versions down to 3.7, while changes in #23952 is for 3.10 only. If those changes are mixed in one PR, would that be harder to backport? |
This PR is stale because it has been open for 30 days with no activity. |
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 |
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.
Ideally we should link to the documentation for the __future__
statement, not to the PEP directly. A PEP is a change proposal, not live documentation.
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 |
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.
that is a dictionary mapping from variable names (mangled if private) to the | |
that is a dictionary mapping from variable names (mangled if private) to |
Reads better without the article
|
||
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 |
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.
Really? That seems like a bug.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Currently, the documentation for variable annotations does not mention PEP 563 at all. This PR tries to improve this.
Note: this is describing the situation when #23952 is not applied, so that this PR can be easily backported to earlier versions of Python. We may need to either update #23952 itself or create a new PR to update the doc to demonstrate that annotations for complex targets will no longer be evaluated when PEP 563 is enabled.
https://bugs.python.org/issue42737