I’ve started playing around with a similar idea, but using a private namespace and global for exports.
Essentially, you could write something like:
# my_mod.py
@namespace
def __private__():
def private_func() -> int: ...
global public_func
def public_func() -> int:
return private_func()
This would allow monkeypatching via my_mod.__private__ while still allowing code in my_mod.py to access everything freely.
I’d be +1 on adding a namespace block (and maybe allowing global def/global class?).[1]
(My current implementation of
@namespaceis quite hacky, although requiring areturn locals()at the end would make it much simpler.) ↩︎