[Python-ideas] Function-like Modules (better control/introspection)
Guido van Rossum
guido at python.org
Mon Mar 17 18:24:08 CET 2014
I don't know whether it's worth the savings, but the __code__ for a
module's toplevel is thrown away because it is not needed after it has run.
Reading it back from disk is wasteful if you do it every time for every
module, but how often is it used in a situation where speed matters?
Saving __code__ might be useful so you can tell with certainty which code
was run -- the file may have been modified since it was imported.
On Mon, Mar 17, 2014 at 10:11 AM, Antoine Pitrou <solipsis at pitrou.net>wrote:
> 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.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140317/e25b80ff/attachment.html>
More information about the Python-ideas
mailing list