[Python-Dev] Meta coding in Python (original) (raw)

Benjamin Peterson benjamin at python.org
Fri Sep 16 00:57:12 CEST 2011


2011/9/15 Albert Zeyer <albzey at googlemail.com>:

Hi list,

I thought it would be nice in Python to allow some sort of meta coding (which goes far ahead of simple function descriptors). The most straight forward way would be to allow operations on the AST. I wrote a small patch for CPython 2.7.1 which, for each code object, adds the related AST of the statement to a new attribute coast. https://github.com/albertz/CPython/commit/2670e621458fd80311fc02897b698ea2a36d494b Some simple demonstration of what you can do with this: https://github.com/albertz/CPython/blob/astcompilepatch/testcoast.py I'm not sure wether the Python AST in this form is optimal for doing such things, though. Maybe another representation would be more efficient and result in simpler code for doing transformations.

It would be useful, but is a waste of memory is 99.99% of programs.

-- Regards, Benjamin



More information about the Python-Dev mailing list