Comment by zahlman

2 days ago

This one is arguably even more of a hack; it's working at the source code level rather than the AST level.

The "coding" here is a bytes-to-text encoding. The Python lexer expects to see character data; you get to insert arbitrary code to convert the bytes to characters (or just use existing schemes the implement standards like UTF-8).

> it's working at the source code level rather than the AST level.

this (lexing) is the only use of the codec hack - if you want to manipulate the AST you do not need this and can just to `ast.parse` and then recompile the function.

  • Indeed; the goto hack works that way (and uses a decorator to make it easier to invoke the AST-manipulation logic).