logoalt Hacker News

dkerstentoday at 9:27 AM1 replyview on HN

Once upon a time I tried to write such a decorator too in python 2.x and the byteplay bytecode disassembler library. I was trying to do the conversion at the bytecode level instead of transforming the AST. I believe I got as far as detecting simple self recursive functions, but never actually managed to implement the actual transformation.


Replies

lioeterstoday at 10:20 AM

That is an ambitious idea, and I applaud anyone who attempts such heights even if it turned out to be impractical.

OP's approach is surprisingly straight forward, only a few hundred lines.

https://github.com/raaidrt/tacopy/blob/main/src/tacopy/trans...