PEP 563 also requires using ``eval()`` or ``typing.get_type_hints()``to examine annotations. Code updated to work with PEP 563 that calls``eval()`` directly would have to be updated simply to remove the``eval()`` call. Code using ``typing.get_type_hints()`` wouldcontinue to work unchanged, though future use of that functionwould become optional in most cases.
Because this PEP makes semantic changes to how annotations areevaluated, this PEP will be initially gated with a per-module``from __future__ import co_annotations`` before it eventuallybecomes the default behavior.
* *Code that sets annotations on module or class attributesfrom inside any kind of flow control statement.* It'scurrently possible to set module and class attributes withannotations inside an ``if`` or ``try`` statement, and it worksas one would expect. It's untenable to support this behaviorwhen this PEP is active.
type_ = int
type_ = float
* *Code in module or class scope that references or modifies thelocal* ``__annotations__`` *dict directly.* Currently, whensetting annotations on module or class attributes, the generatedcode simply creates a local ``__annotations__`` dict, then setsmappings in it as needed. It's also possible for user codeto directly modify this dict, though this doesn't seem like it'san intentional feature. Although it would be possible to supportthis after a fashion when this PEP was active, the semanticswould likely be surprising and wouldn't make anyone happy.
Attached is my second draft of PEP 649. The PEP and the prototype have both seen a marked improvement since round 1 in January; PEP 649 now allows annotations to refer to any variable they could see under stock semantics:
- Local variables in the current function scope or in enclosing function scopes become closures and use LOAD_DEFER.
- Class variables in the current class scope are made available using a new mechanism, in which the class dict is attached to the bound annotation function, then loaded into f_locals when the annotation function is run. Thus permitting LOAD_NAME opcodes to function normally.
I look forward to your comments,
/arry_______________________________________________Python-Dev mailing list -- email@example.comTo unsubscribe send an email to firstname.lastname@example.orgMessage archived at https://email@example.com/message/QSASX6PZ3LIIFIANHQQFS752BJYFUFPY/Code of Conduct: http://python.org/psf/codeofconduct/