[Python-Dev] advice needed: best approach to enabling "metamodules"?

Mark Shannon mark at hotpy.org
Sat Nov 29 17:46:27 CET 2014


On 29/11/14 01:59, Nathaniel Smith wrote:
> Hi all,
>
[snip]
>
> Option 3: Make it legal to assign to the __dict__ attribute of a
> module object, so that we can write something like
>
>     new_module = MyModuleSubclass(...)
>     new_module.__dict__ = sys.modules[__name__].__dict__
>     sys.modules[__name__].__dict__ = {}     # ***
>     sys.modules[__name__] = new_module
>

Why does MyModuleClass need to sub-class types.ModuleType?
Modules have no special behaviour, apart from the inability to write
to their __dict__ attribute, which is the very thing you don't want.

If it quacks like a module...

Cheers,
Mark.


More information about the Python-Dev mailing list