diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-06-15 15:18:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-15 15:18:16 (GMT) |
commit | 9e0b11eb21930b7b8e4a396200a921e9985cfca4 (patch) | |
tree | a43b09d05f11696684ab71dc6cedd2257e480e46 /Doc/reference | |
parent | 6f63dfff6f493b405f3422210a168369e1e7a35d (diff) | |
download | cpython-9e0b11eb21930b7b8e4a396200a921e9985cfca4.zip cpython-9e0b11eb21930b7b8e4a396200a921e9985cfca4.tar.gz cpython-9e0b11eb21930b7b8e4a396200a921e9985cfca4.tar.bz2 |
annotations: expand documentation on "simple" assignment targets (#120535)
This behavior is rather surprising and it was not clearly specified.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/simple_stmts.rst | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index a253482..4f6c0c6 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -333,7 +333,9 @@ statement, of a variable or attribute annotation and an optional assignment stat The difference from normal :ref:`assignment` is that only a single target is allowed. -For simple names as assignment targets, if in class or module scope, +The assignment target is considered "simple" if it consists of a single +name that is not enclosed in parentheses. +For simple assignment targets, if in class or module scope, the annotations are evaluated and stored in a special class or module attribute :attr:`__annotations__` that is a dictionary mapping from variable names (mangled if private) to @@ -341,7 +343,8 @@ evaluated annotations. This attribute is writable and is automatically created at the start of class or module body execution, if annotations are found statically. -For expressions as assignment targets, the annotations are evaluated if +If the assignment target is not simple (an attribute, subscript node, or +parenthesized name), the annotation is evaluated if in class or module scope, but not stored. If a name is annotated in a function scope, then this name is local for |