[Python-Dev] advice needed: best approach to enabling "metamodules"?
Steven D'Aprano
steve at pearwood.info
Sun Nov 30 00:05:05 CET 2014
On Sun, Nov 30, 2014 at 11:07:57AM +1300, Greg Ewing wrote:
> Nathaniel Smith wrote:
> >So pkgname/__new__.py might look like:
> >
> > import sys
> > from pkgname._metamodule import MyModuleSubtype
> > sys.modules[__name__] = MyModuleSubtype(__name__, docstring)
> >
> >To start with, the 'from
> >pkgname._metamodule ...' line is an infinite loop,
>
> Why does MyModuleSubtype have to be imported from pkgname?
> It would make more sense for it to be defined directly in
> __new__.py, wouldn't it? Isn't the purpose of separating
> stuff out into __new__.py precisely to avoid circularities
> like that?
Perhaps I'm missing something, but won't that imply that every module
which wants to use a "special" module type has to re-invent the wheel?
If this feature is going to be used, I would expect to be able to re-use
pre-written module types. E.g. having written "module with properties"
(so to speak) once, I can just import it and use it in my next project.
--
Steven
More information about the Python-Dev
mailing list