[Python-Dev] Standardise the AST (Re: PEP 563: Postponed Evaluation of Annotations) (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Nov 12 17:39:05 EST 2017


Guido van Rossum wrote:

The PEP answers that clearly (under Implementation):

> If an annotation was already a string, this string is preserved > verbatim.

This bothers me, because it means the transformation from what you write in the source and the object you get at run time is not reversible. Something interpreting the annotations as Python expressions at run time has no way to know whether a Python expression was written in the source or a string literal whose contents happen to look like an expression.

I still think that the run-time form of a non-evaluated annotation should be some form of AST. That's been rejected on the grounds that the structure of an AST is considered an implementation detail that can change between Python versions.

However, that in itself seems like a bad thing to me. There should be a standard and stable form of AST provided that doesn't change unless the syntax of Python changes. It doesn't have to be the same as what's used internally by the compiler.

Proponents of Lisp point to the advantages of easily being able to express Lisp programs using Lisp data structures. There would also be benefits in having a standard way to represent Python programs using Python data structures.

-- Greg



More information about the Python-Dev mailing list