Re:A function decorator that rewrites the bytecode to enable...
by pjmlp on Tuesday September 21, 2021 @04:17AM
(#28603019)
Back in 1999 we used similar arcane techniques to ship encrypted Tcl scripts.
Re:A function decorator that rewrites the bytecode to enable...
by AshamedCaptain on Tuesday September 21, 2021 @09:36AM
(#28604892)
And probably still do the same today...
Re:A function decorator that rewrites the bytecode to enable...
by borzunov on Tuesday September 21, 2021 @11:14AM
(#28605848)
I do the same in my module that enables increment operators in Python by patching the bytecode for two unary plus/minus ops: https://github.com/borzunov/plusplus
As a practical application, pytest uses this to take the statement `assert foo == bar` and rewrite the AST into a number of instructions that extract the values of foo and bar and print them if the assertion fails: http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests... (https://docs.pytest.org/en/6.2.x/assert.html for those unfamiliar with the library) - so if you use pytest, you're already relying on these arcane techniques!