[Python-ideas] Function-like Modules (better control/introspection)

Antoine Pitrou solipsis at pitrou.net
Mon Mar 17 18:11:55 CET 2014


On Tue, 18 Mar 2014 02:36:31 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 18 Mar 2014 01:59, "C Anthony Risinger" <anthony at xtfx.me> wrote:
> >
> > ok, let me try this again, sans distractions:
> >
> > could we consider adding __code__ and __call__ to module objects?
> __code__ would contain the code executed in the module __dict__, and
> __call__ would reload the module.
> >
> > thoughts?
> 
> The question to ask is: what would such a change make possible that
> importlib doesn't already handle?

I suppose module.__code__ would be a lot less wasteful than
module.__loader__.get_code(module.__name__) (which seems to reload the
bytecode from disk every time).

(while looking at this, I was surprised that dis.dis(some_module)
1) doesn't show a disassembly for the module toplevel 2) shows
disassembly for objects which some_module imports from other modules)

Regards

Antoine.




More information about the Python-ideas mailing list