[Python-Dev] cpython: Introduce importlib.util.ModuleManager which is a context manager to (original) (raw)
R. David Murray rdmurray at bitdance.com
Wed May 29 18:49:43 CEST 2013
- Previous message: [Python-Dev] cpython: Introduce importlib.util.ModuleManager which is a context manager to
- Next message: [Python-Dev] cpython: Introduce importlib.util.ModuleManager which is a context manager to
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 29 May 2013 12:25:45 -0400, Brett Cannon <brett at python.org> wrote:
In case you want to suggest a name, the context manager returns the module that should be initialized/loaded. So typical usage will be::
class Loader: def loadmodule(self, fullname): with importlib.util.moduletoinit(fullname) as module: # Load/initialize the module return module Basically the manager either gets the module from sys.modules if it is already there (a reload) or creates a new module and sticks it into sys.modules so other imports will grab the right module object. If there is an exception and the module was new, it deletes it from sys.modules to prevent stale modules from sticking around.
So it is a context manager to handle the exception? Now I think I see where Nick is coming from.
How about 'managed_initializiation'? That seems closer to the 'closing' model, to me. It isn't as clear about what it is returning, though, since you are passing it a name and getting back a module, whereas in the closing case you get back the same object you send in.
Perhaps 'managed_module'?
--David
- Previous message: [Python-Dev] cpython: Introduce importlib.util.ModuleManager which is a context manager to
- Next message: [Python-Dev] cpython: Introduce importlib.util.ModuleManager which is a context manager to
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]