[issue17515] Add sys.setasthook() to allow to use a custom AST optimizer

STINNER Victor report at bugs.python.org
Fri Mar 22 01:58:11 CET 2013


New submission from STINNER Victor:

I wrote an optimizer rewriting the AST to implement various optimizatoions:
https://bitbucket.org/haypo/astoptimizer

To be able to use it, or use any other kind of AST transformation, I propose to add a new sys.setasthook() function to set a custom AST hook.

Attached patch is a proof-of-concept. The patch should be improved: document the function and add write unit tests.

Prototype of the hook:

def asthook(ast, filename):
   # ...
   return new_ast

I don't know if we need to add a compiler option (like _ast.PyCF_ONLY_AST) to skip the hook.

----------
files: setasthook.patch
keywords: patch
messages: 184932
nosy: brett.cannon, haypo
priority: normal
severity: normal
status: open
title: Add sys.setasthook() to allow to use a custom AST optimizer
versions: Python 3.4
Added file: http://bugs.python.org/file29539/setasthook.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17515>
_______________________________________


More information about the Python-bugs-list mailing list