On 2017-09-11, C Anthony Risinger wrote:
> I'm getting at, is can we find a way to make modules a real type? So dunder
> methods are activated? This would make modules phenomenally powerful
> instead of just a namespace (or resorting to after the fact __class__
> reassignment hacks).

My __namespace__ idea will allow this.  A module can be a singleton
instance of a singleton ModuleType instance.  So, you can assign a
property like:

    <this module>.__class__.prop = <property>

and have it just work.  Each module would have a singleton class
associated with it to store the properties.  The spelling of
<this module> will need to be worked out.  It could be
sys.modules[__name__].__class__ or perhaps we can have a weakref, so
this:

    __module__.__class__.prop = ...

Need to think about this.

I have done import hooks before and I know the pain involved.
importlib cleans things up a lot.  However, if my early prototype
work is an indication, the import stuff gets a whole lot simpler.
Instead of passing around a dict and then grubbing around
sys.modules because the module is actually what you want, you just
pass the module around directly.

Thanks for you feedback.

Regards,

  Neil
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to