- Currently, it supports only very simple functions (functions with 1 statement).
- It is far from trivial to support non-simple functions, or basically any functions which needs its own local variables / its own stack. This is possible via a custom stack object for this purpose, but this all need some extra logic and transformation for the local variable handling.
It does some similar hacks, i.e. modifies functions, but all on the bytecode level. I.e. no import hook hacks, it uses the code objects and patches them. This makes some things easier and some other things harder.
On the AST level, you have symbol names, so they become ambiguous. E.g.
@inline
def f(y):
x = y + 1
return x
def g():
x = 42
f(0)
return x
print g()
would print 1.
When you do it on the bytecode level, many things probably would work, although I don't know whether some things might get confused when there are multiple variables with the same name. Also, accessing `locals()` would (of course) not work.
Woah, I didn't expect this to get any interest on HNews. This is a major hack that I did during some downtime at work, I think its pretty neat but its entirely useless. I'm glad other people find it interesting!
- Currently, it supports only very simple functions (functions with 1 statement).
- It is far from trivial to support non-simple functions, or basically any functions which needs its own local variables / its own stack. This is possible via a custom stack object for this purpose, but this all need some extra logic and transformation for the local variable handling.
Btw., if you are interested in this, you might also be interested in my project: https://github.com/albertz/PythonHotswap
It does some similar hacks, i.e. modifies functions, but all on the bytecode level. I.e. no import hook hacks, it uses the code objects and patches them. This makes some things easier and some other things harder.