]> granicus.if.org Git - python/commit
Issues #18088, 18089: Introduce
authorBrett Cannon <brett@python.org>
Fri, 31 May 2013 22:56:47 +0000 (18:56 -0400)
committerBrett Cannon <brett@python.org>
Fri, 31 May 2013 22:56:47 +0000 (18:56 -0400)
commit0dbb4c7f1338d1391e7214b564ef4638bc257347
treed9bd89758691c3b739c68e7eb50b444b15186bd1
parentf1d7b11db905db5b40e2d97fa21af06871cf89ff
Issues #18088, 18089: Introduce
importlib.abc.Loader.init_module_attrs() and implement
importlib.abc.InspectLoader.load_module().

The importlib.abc.Loader.init_module_attrs() method sets the various
attributes on the module being loaded. It is done unconditionally to
support reloading. Typically people used
importlib.util.module_for_loader, but since that's a decorator there
was no way to override it's actions, so init_module_attrs() came into
existence to allow for overriding. This is also why module_for_loader
is now pending deprecation (having its other use replaced by
importlib.util.module_to_load).

All of this allowed for importlib.abc.InspectLoader.load_module() to
be implemented. At this point you can now implement a loader with
nothing more than get_code() (which only requires get_source();
package support requires is_package()). Thanks to init_module_attrs()
the implementation of load_module() is basically a context manager
containing 2 methods calls, a call to exec(), and a return statement.
Doc/library/importlib.rst
Doc/whatsnew/3.4.rst
Lib/importlib/_bootstrap.py
Lib/importlib/abc.py
Lib/importlib/util.py
Lib/test/test_importlib/source/test_file_loader.py
Lib/test/test_importlib/test_abc.py
Lib/test/test_importlib/test_util.py
Misc/NEWS
Python/importlib.h