New improved version:
def submodule(f):
co = f.__code__
i = len(co.co_consts)
b = bytes([0x64, i, 0x83, 0x0, 0x53, 0x0])
f.__code__ = co.replace(
co_consts = co.co_consts + (locals,),
co_code = co.co_code[:-4] + b
)
return type(f.__name__, (), f())
@submodule
def Stuff():
def f1():
print("First function")
f2()
def f2():
print("Second function")
Stuff.f1()
--
Greg
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/D2PZFBS4JWES5L3Y5X2GPQSWPC7G45ZF/
Code of Conduct: http://python.org/psf/codeofconduct/