Skip to content
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

implement PEP-563: annotations as strings #2863

scoder opened this Issue Feb 23, 2019 · 0 comments


None yet
1 participant
Copy link

scoder commented Feb 23, 2019

I 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) in
  • Give it visitor methods for all nodes that can have annotations (any ExprNode, and anything that has an annotation attribute in
  • If the node has an annotation, serialise it using the code writer and replace the existing node.annotation with a StringNode' (or UnicodeNode` ?) that wraps the string value.
  • Add the new transform to the pipeline in, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.