* Change code_transformer() API. The method now takes a code object as input
  and must return a code object.
* Be more explicit: code_transformer() and ast_transformer() are methods taking
  a self parameter.
This commit is contained in:
Victor Stinner 2016-01-27 11:29:51 +01:00
parent d45c401bb2
commit 3910522c12
1 changed files with 12 additions and 12 deletions

View File

@ -263,32 +263,32 @@ to join code transformer names to build the optimizer tag.
``PyParser_ASTFromStringObject()``.
code_transformer()
------------------
code_transformer() method
-------------------------
Prototype::
def code_transformer(code, consts, names, lnotab, context):
def code_transformer(self, code, context):
...
return (code, consts, names, lnotab)
new_code = ...
...
return new_code
Parameters:
* *code*: the bytecode (``bytes``)
* *consts*: a sequence of constants
* *names*: tuple of variable names
* *lnotab*: table mapping instruction offsets to line numbers
(``bytes``)
* *code*: code object
The method must return a code object.
The code transformer is run after the compilation to bytecode
ast_transformer()
------------------
ast_transformer() method
------------------------
Prototype::
def ast_transformer(tree, context):
def ast_transformer(self, tree, context):
...
return tree