[Python-Dev] AST optimizer implemented in Python

PJ Eby pje at telecommunity.com
Sun Aug 12 20:23:55 CEST 2012


On Sat, Aug 11, 2012 at 8:03 PM, Brett Cannon <brett at python.org> wrote:
>
> It would also be very easy to expand importlib.abc.SourceLoader to add a
> method which is called with source and returns the bytecode to be written
> out which people could override with AST optimizations before sending the
> bytecode back. That way we don't have to get into the whole business of AST
> transformations if we don't want to (although, as Victor pointed out, there
> are some people who do want this formally supported).

I'm not sure if this is directly related or not, but making this
mechanism support custom compilation for new filename suffixes would
be nice, especially for various e.g. HTML/XML templating systems that
compile to Python or bytecode.

Specifically, having a way to add a new source suffix (e.g. ".kid",
".zpt", etc.) and a matching compilation function, such that it's
automatically picked up for compilation by both the filesystem and zip
importers would be awesome.  It'd also allow for DSLs and syntax
experiments using alternative filename extensions.


More information about the Python-Dev mailing list