Guide to the examples
The examples included are listed roughly in increasing level of complexity. Source transformations and AST transformations can be used interactively in IPython/Jupyter environments; bytecode transformations and custom encoding cannot.
Source transformations
Source transformations represent one of the easiest way to introduce new experimental syntax in Python. If you want to write your own import hook, it might be worth your while reading a few of the following examples, if not all of them, especially including examining the source code.
Important
This entire project is meant as enabling easy experiments with changes to Python’s normal syntax. Some (most?) of the examples are definitely not reliable enough to be included in code used by anyone other than yourself.
AST transformations
Todo
Currently, only one AST example exists and only one AST transformation can be done. A second example should be created and find a way to ensure that both could be applied.
AST creation
Bytecode transformations
Todo
Currently, only one Bytecode example exists and only one Bytecode transformation can be done. A second example should be created and find a way to ensure that both could be applied.
More complex examples
Tranforming a module after creation
Todo
Currently, a patch requires to specify a module name for it to be applied
to that module.
It might be worthwhile exploring a case where we use "*"
to specify that the patch should be applied to all modules.
Custom encoding
Import hooks are not the only way one can transform a source; this can also be done by custom encodings.