|
I'm going to hell for this, but here goes. A couple years back I wrote a library called Transformana ( https://github.com/daeken/Transformana ) which allows you to manipulate ASTs via 'macros' in decorators. I apologize from the bottom of my heart to anyone who ends up maintaining code that utilizes this, but have fun. https://github.com/daeken/Transformana/blob/master/test.py shows off various features if you're interested. Edit: Here's the output from running the test, in case you want to see the AST format. Hello world!
Yep, working.
Don't know.
['function',
None,
'test2',
(),
(),
0,
None,
['stmt', [['printnl', [['const', 'Hello from test2']], None]]]]
Hello from test2
['function', None, 'test3', (), (), 0, None, ['stmt', [['printnl', [['const', 'This should never be callable']], None]]]]
|
https://github.com/built/Jane-Kelly/blob/master/guard.py
It'll let you redefine functions with different guard parameters. (@when("x=5"), @when("x>20"), etc.) Like you, I would also shudder to see this in production. But it was fun and shows off some of what's possible.