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

Antoine Pitrou solipsis at pitrou.net
Sat Nov 29 21:18:58 CET 2014


On Sat, 29 Nov 2014 20:02:50 +0000
Nathaniel Smith <njs at pobox.com> wrote:
> >
> > Option 1b: have __class__ assignment delegate to a tp_classassign slot
> > on the old class, so that typeobject.c doesn't have to be cluttered with
> > many special cases.
> 
> I'm intrigued -- how would this help?

It would allow ModuleType to override tp_classassign to decide whether
and how __class__ assignment on a module instance is allowed to work.
So typeobject.c needn't know about any specifics of ModuleType or any
other type.

> > How do these two options interact with the fact that module functions
> > store their globals dict, not the module itself?
> 
> I think that's totally fine? The whole point of all these proposals is
> to make sure that the final module object does in fact have the
> correct globals dict.
> 
> ~$ git clone git at github.com:njsmith/metamodule.git

Ok, I see. The code hacks up the new module to take ownership of the
old module's __dict__. That doesn't look very clean to me.

Regards

Antoine.


More information about the Python-Dev mailing list