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
On Tue, 18 Mar 2014 02:36:31 +1000 Nick Coghlan
wrote: On 18 Mar 2014 01:59, "C Anthony Risinger"
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@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)