[Python-Dev] PEP 451 update (original) (raw)

PJ Eby pje at telecommunity.com
Sun Oct 27 17:37:00 CET 2013


On Sun, Oct 27, 2013 at 1:03 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

Now, regarding the signature of execmodule(): I'm back to believing that loaders should receive a clear indication that a reload is taking place. Legacy loaders have to figure that out for themselves (by seeing that the module already exists in sys.modules), but we can do better for the new API by making the execmodule signature look like:

def execmodule(self, module, previousspec=None): # module is as per the current PEP 451 text # previousspec would be set only in the reload() case # loaders that don't care still need to accept it, but can just ignore it

Just to be clear, this means that a lazy import implementation that creates a module object without a spec in the first place will look like an initial import? Or will that crash importlib because of a missing spec attribute?

That is, is reload()'s contract adding a new prerequisite for the object passed to it?

(The specific use case is creating a ModuleType subclass instance for lazy importing upon attribute access. Pre-importlib, all that was needed was a working name attribute on the module.)



More information about the Python-Dev mailing list