implement PEP-563: annotations as strings
See original GitHub issueI think Cython 3.0 would also be a good time to implement PEP-563 (“Postponed Evaluation of Annotations”). There already is a Cython code generator in Cython.CodeWriter
that can be used to generate the expression string. This should be done somewhat late in the compiler pipeline since some optimisations can make use of the annotation information. It might be worth creating a separate transformation before the code generation.
What needs to be done:
- Implement a new transform
class SerialiseAnnotations(VisitorTransform)
inParseTreeTransforms.py
. - Give it visitor methods for all nodes that can have annotations (any
ExprNode
, and anything that has anannotation
attribute inNodes.py
). - If the node has an annotation, serialise it using the code writer and replace the existing
node.annotation
with aStringNode' (or
UnicodeNode` ?) that wraps the string value. - Add the new transform to the pipeline in
Pipeline.py
, rather late, before the final checks. - Extend the existing annotation related tests in
tests/run/
to cover the annotation string value. Add new tests for expressions that are not covered yet.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
PEP 563 – Postponed Evaluation of Annotations
Implementation. With this PEP, function and variable annotations will no longer be evaluated at definition time. Instead, a string form will ...
Read more >PEP 563 and PEP 649 - Łukasz Langa
PEP 563 is often criticized for making the contents of __annotations__ strings. The idea of a string annotation doesn't come from PEP 563...
Read more >python 3.x - How to resolve type annotations to function local ...
In Python 4.0, type annotations like foo:int. will be treated as a string and need to be dynamically resolved. This can be selected...
Read more >Annotation issues at runtime - mypy 0.991 documentation
Annotation issues at runtime#. Idiomatic use of type annotations can sometimes run up against what a given version of Python considers legal code....
Read more >[Python-Dev] PEP 563 and 649: The Great Compromise
The heart of the debate between PEPs 563 and 649 is the question: what should an annotation be? Should it be a string...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any help is appreciated.
@nihilist-banana, there is a description of the implementation steps in the ticket, and the HackerGuide has some general information about how to get started. Does this help already, or otherwise, could you maybe ask on the
cython-devel
mailing list if you need more specific guidance?