question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implement PEP-563: annotations as strings

See original GitHub issue

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 ParseTreeTransforms.py.
  • Give it visitor methods for all nodes that can have annotations (any ExprNode, and anything that has an annotation attribute in Nodes.py).
  • 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 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:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scodercommented, Aug 14, 2019

Any help is appreciated.

1reaction
scodercommented, May 14, 2019

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found