Use a with block to control export (public/private/__all__)

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]


  1. (My current implementation of @namespace is quite hacky, although requiring a return locals() at the end would make it much simpler.) ↩︎