Commit Graph

111 Commits

Author SHA1 Message Date
Brett Cannon a87e31ca52 Issue #18955: clarify what is removed by importlib.util.module_for_loader. 2013-09-13 16:52:19 -04:00
Brett Cannon 27bc441f5e merge for issue #18278 2013-06-21 18:37:02 -04:00
Brett Cannon 29b2f174da Issue #18278: properly document how the loaders are called for FileFinder 2013-06-21 18:31:55 -04:00
Brett Cannon a81d527ca9 documentation suggesting something which doesn't exist 2013-06-16 19:17:12 -04:00
Brett Cannon 390f6c1bf7 Merge doc/argument name fix 2013-06-16 19:09:46 -04:00
Brett Cannon 1d75382e81 Fix a misnaming of a method and an argument 2013-06-16 19:06:55 -04:00
Brett Cannon f24fecd4ac Issue #18076: Introduce imoportlib.util.decode_source().
The helper function makes it easier to implement
imoprtlib.abc.InspectLoader.get_source() by making that function
require just the raw bytes for source code and handling all other
details.
2013-06-16 18:37:53 -04:00
Brett Cannon a3c96154d2 Issue #17907: touch up the code for imp.new_module(). 2013-06-14 22:26:30 -04:00
Brett Cannon 05a647deed Issue #18192: Introduce importlib.util.MAGIC_NUMBER and document the
deprecation of imp.get_magic().
2013-06-14 19:02:34 -04:00
Brett Cannon 3fe35e6503 Issue #18193: Add importlib.reload(), documenting (but not
implementing in code) the deprecation of imp.reload().

Thanks to Berker Peksag for the patch.
2013-06-14 15:04:26 -04:00
Brett Cannon 2cefb3cf96 Various tweaks to importlib docs. 2013-05-25 11:26:11 -04:00
Brett Cannon 0dbb4c7f13 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.
2013-05-31 18:56:47 -04:00
Brett Cannon b60a43eabf Add a reset_name argument to importlib.util.module_to_load in order to
control whether to reset the module's __name__ attribute in case a
reload is being done.
2013-05-31 18:11:17 -04:00
Brett Cannon 177381116e Add a reference to module_to_load 2013-05-31 18:00:56 -04:00
Brett Cannon 357c9fb055 Rename importlib.util.ModuleManager to module_to_load so that the name
explains better what the context manager is providing.
2013-05-30 17:31:47 -04:00
Brett Cannon 56dfc2127f Undo a recommendation as load_module() methods might be called directly 2013-05-28 18:40:31 -04:00
Brett Cannon 3dc48d6f69 Issue #18070: importlib.util.module_for_loader() now sets __loader__
and __package__ unconditionally in order to do the right thing for
reloading.
2013-05-28 18:35:54 -04:00
Brett Cannon a22faca714 Clarify some documentation 2013-05-28 17:50:14 -04:00
Brett Cannon a3687f0d68 Introduce importlib.util.ModuleManager which is a context manager to
handle providing (and cleaning up if needed) the module to be loaded.

A future commit will use the context manager in
Lib/importlib/_bootstrap.py and thus why the code is placed there
instead of in Lib/importlib/util.py.
2013-05-28 17:29:34 -04:00
Brett Cannon 3b62ca88e4 Issue #18072: Implement get_code() for importlib.abc.InspectLoader and
ExecutionLoader.
2013-05-27 21:11:04 -04:00
Brett Cannon 9ffe85e1e8 Move importlib.abc.SourceLoader.source_to_code() to InspectLoader.
While the previous location was fine, it makes more sense to have the
method higher up in the inheritance chain, especially at a point where
get_source() is defined which is the earliest source_to_code() could
programmatically be used in the inheritance tree in importlib.abc.
2013-05-26 16:45:10 -04:00
Brett Cannon b39567a00e merge 2013-05-25 11:26:36 -04:00
Brett Cannon 4c14b5de1c #17115,17116: Have modules initialize the __package__ and __loader__
attributes to None.

The long-term goal is for people to be able to rely on these
attributes existing and checking for None to see if they have been
set. Since import itself sets these attributes when a loader does not
the only instances when the attributes are None are from someone
overloading __import__() and not using a loader or someone creating a
module from scratch.

This patch also unifies module initialization. Before you could have
different attributes with default values depending on how the module
object was created. Now the only way to not get the same default set
of attributes is to circumvent initialization by calling
ModuleType.__new__() directly.
2013-05-04 13:56:58 -04:00
Brett Cannon 1f6ee73c1e merge for issue #17357 2013-04-27 23:20:55 -04:00
Brett Cannon 4067aa272e Issue #17357: Use more stern wording for
importlib.invalidate_caches().
2013-04-27 23:20:32 -04:00
Georg Brandl 526575d537 Fix invalid markup. 2013-04-11 16:10:13 +02:00
Brett Cannon 100883f0cb Issue #17093,17566,17567: Methods from classes in importlib.abc now raise/return
the default exception/value when called instead of raising/returning
NotimplementedError/NotImplemented (except where appropriate).
This should allow for the ABCs to act as the bottom/end of the MRO with expected
default results.

As part of this work, also make importlib.abc.Loader.module_repr()
optional instead of an abstractmethod.
2013-04-09 16:59:39 -04:00
Brett Cannon 327992330e Issue #17099: Have importlib.find_loader() raise ValueError when
__loader__ is not set on a module. This brings the exception in line
with when __loader__ is None (which is equivalent to not having the
attribute defined).
2013-03-13 11:09:08 -07:00
Brett Cannon 4802becb16 Issue #17117: Have both import itself and importlib.util.set_loader()
set __loader__ on a module when set to None.

Thanks to Gökcen Eraslan for the fix.
2013-03-13 10:41:36 -07:00
Andrew Svetlov 597ba7e351 Issue #17215: Fix documentation misprints (patch by July Tikhonov) 2013-02-17 16:56:28 +02:00
Andrew Svetlov a60de4f14f Issue #17215: Fix documentation misprints (patch by July Tikhonov) 2013-02-17 16:55:58 +02:00
Eric Snow a6cfb28bd2 Issue #15627: This is simply an update to the name of a new method recently added
to importlib.abc.SourceLoader.
2012-12-04 23:43:43 -08:00
Brett Cannon 5650e4f41c Issue #15627: Add the compile_source() method to
importlib.abc.SourceLoader.

This provides an easy hook into the import system to allow for source
transformations, AST optimizations, etc.
2012-11-18 10:03:31 -05:00
Brett Cannon 10f19812b5 Merge fix for #16489 from 3.3 2012-11-17 09:33:14 -05:00
Brett Cannon 56b4ca78d8 Issue #16489: Make it clearer that importlib.find_loader() requires
the user to import any parent packages.
2012-11-17 09:30:55 -05:00
Andrew Svetlov 90a654b1dd Issue #15641: Clean up deprecated classes from importlib
Patch by Taras Lyapun.
2012-11-05 09:34:46 +02:00
Ezio Melotti 1f67e80564 Fix typo. 2012-10-21 07:24:13 +03:00
Brett Cannon 1b79918641 Issue #15640: Document importlib.abc.Finder as deprecated.
The code for the class itself isn't deprecated for
backwards-compatibility reasons, but the class shouldn't be directly
inherited by anyone anymore as the API is no longer as widely valid as
it used to be.
2012-08-17 14:08:24 -04:00
R David Murray 27bbcfb8ff Merge #15543: glossary entry for and 'universal newlines', and links to it.
Patch by Chris Jerdonek.
2012-08-15 11:11:27 -04:00
R David Murray ee0a945ae4 #15543: reflow paragraphs. 2012-08-15 11:05:36 -04:00
R David Murray 1b00f25bf9 #15543: glossary entry for and 'universal newlines', and links to it.
Patch by Chris Jerdonek.
2012-08-15 10:43:58 -04:00
Andrew Svetlov a86565465a Push importlib ABC hierarchy chart. 2012-08-13 22:19:01 +03:00
Brett Cannon a6e8581449 Minor doc formatting cleanup. 2012-08-11 19:41:27 -04:00
Brett Cannon ac9f2f3de3 Issue #15576: Allow extension modules to be a package's __init__
module again. Also took the opportunity to stop accidentally exporting
_imp.extension_suffixes() as public.
2012-08-10 13:47:54 -04:00
Brett Cannon f4dc9204cc Issue #15502: Finish bringing importlib.abc in line with the current
state of the import system. Also make importlib.invalidate_caches()
work with sys.meta_path instead of sys.path_importer_cache to
completely separate the path-based import system from the overall
import system.

Patch by Eric Snow.
2012-08-10 12:21:12 -04:00
Brett Cannon cb4996afe4 Issue #15471: Don't use mutable object as default values for the
parameters of importlib.__import__().
2012-08-06 16:34:44 -04:00
Brett Cannon 077ef45a74 Update the What's New details for importlib based on doc/ABC changes. 2012-08-02 17:50:06 -04:00
Brett Cannon 773468f3a9 Ditch the 'self' argument in importlib docs since it's implied. 2012-08-02 17:35:34 -04:00
Nick Coghlan 4941774f59 Issue #15502: Bring the importlib.PathFinder docs and docstring more in line with the new import system documentation, and fix various parts of the new docs that weren't quite right given PEP 420 or were otherwise a bit misleading. Also note the key terminology problem still being discussed in the issue 2012-08-02 23:03:58 +10:00
Nick Coghlan ff79486bb5 Close #15519: Properly expose WindowsRegistryFinder in importlib and bring the name into line with normal import terminology. Original patch by Eric Snow 2012-08-02 21:45:24 +10:00