PEP 511
* 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:
parent
d45c401bb2
commit
3910522c12
24
pep-0511.txt
24
pep-0511.txt
|
@ -263,32 +263,32 @@ to join code transformer names to build the optimizer tag.
|
||||||
``PyParser_ASTFromStringObject()``.
|
``PyParser_ASTFromStringObject()``.
|
||||||
|
|
||||||
|
|
||||||
code_transformer()
|
code_transformer() method
|
||||||
------------------
|
-------------------------
|
||||||
|
|
||||||
Prototype::
|
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:
|
Parameters:
|
||||||
|
|
||||||
* *code*: the bytecode (``bytes``)
|
* *code*: code object
|
||||||
* *consts*: a sequence of constants
|
|
||||||
* *names*: tuple of variable names
|
The method must return a code object.
|
||||||
* *lnotab*: table mapping instruction offsets to line numbers
|
|
||||||
(``bytes``)
|
|
||||||
|
|
||||||
The code transformer is run after the compilation to bytecode
|
The code transformer is run after the compilation to bytecode
|
||||||
|
|
||||||
|
|
||||||
ast_transformer()
|
ast_transformer() method
|
||||||
------------------
|
------------------------
|
||||||
|
|
||||||
Prototype::
|
Prototype::
|
||||||
|
|
||||||
def ast_transformer(tree, context):
|
def ast_transformer(self, tree, context):
|
||||||
...
|
...
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue