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

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Nov 13 16:36:32 EST 2017


Guido van Rossum wrote:
> But Python's syntax changes in nearly every release.

The changes are almost always additions, so there's no
reason why the AST can't remain backwards compatible.

> the AST level ... elides many details 
> (such as whitespace and parentheses).

That's okay, because the AST is only expected to
represent the semantics of Python code, not its
exact lexical representation in the source. It's
the same with Lisp -- comments and whitespace have
been stripped out by the time you get to Lisp
data.

> Lisp had almost no syntax so I presume the mapping to data structures 
> was nearly trivial compared to Python.

Yes, the Python AST is more complicated, but we
already have that much complexity in the AST being
used by the compiler.

If I understand correctly, we also have a process
for converting that internal structure to and from
an equally complicated set of Python objects, that
isn't needed by the compiler and exists purely for
the convenience of Python code.

I can't see much complexity being added if we were
to decide to standardise the Python representation.

-- 
Greg


More information about the Python-Dev mailing list