3 ms·
I don't understand the reasoning why the transformation directly on the source code is better than on the AST level? Because you can use coding and then it's s
by albertzeyer 4y ago
I don't understand the reasoning why the transformation directly on the source code is better than on the AST level?
Because you can use coding and then it's somewhat automatic?
But you can do sth similar on AST level, namely installing a meta path finder, i.e. an import module hook which does the AST transformation automatically (https://docs.python.org/3/library/sys.html#sys.meta_path https://docs.python.org/3/library/sys.html#sys.meta_path).
Then, there is also the new frame evaluation API (https://peps.python.org/pep-0523/ https://peps.python.org/pep-0523/), which allows you to dynamically rewrite bytecode. This has been used by PyTorch 2.0 for torch.compile.
- deleted 4y ago[deleted]
- traverseda 4y agoThat only work in an import statement, not when you run the code directly.
- adrianmonk 4y agoIn part 1, they say, "I wanted it to look like a regular for-loop from C as much as possible." The AST method seems to require you to write "with _for" instead of "for". The method in part 3 allows you to write "for", which is closer. So presumably it's better because it gets closer to the objective, although at quite a cost of course.