[Python-checkins] r69632 - peps/trunk/pep-0302.txt

brett.cannon python-checkins at python.org
Sun Feb 15 07:06:09 CET 2009


Author: brett.cannon
Date: Sun Feb 15 07:06:09 2009
New Revision: 69632

Log:
Specify what a loader must do if a load fails.


Modified:
   peps/trunk/pep-0302.txt

Modified: peps/trunk/pep-0302.txt
==============================================================================
--- peps/trunk/pep-0302.txt	(original)
+++ peps/trunk/pep-0302.txt	Sun Feb 15 07:06:09 2009
@@ -251,21 +251,16 @@
       the loader must create a new module object and add it to
       sys.modules.
 
-      In C code, all of these requirements can be met simply by using
-      the PyImport_AddModule() function, which returns the existing
-      module or creates a new one and adds it to sys.modules for you.
-      In Python code, you can use something like:
-
-        module = sys.modules.setdefault(fullname, new.module(fullname))
-
-      to accomplish the same results.
-
       Note that the module object *must* be in sys.modules before the
       loader executes the module code.  This is crucial because the
       module code may (directly or indirectly) import itself; adding
       it to sys.modules beforehand prevents unbounded recursion in the
       worst case and multiple loading in the best.
 
+      If the load fails, the loader needs to remove any module it may have
+      inserted into sys.modules. If the module was already in
+      sys.modules then the loader should leave it alone.
+
     - The __file__ attribute must be set.  This must be a string, but it
       may be a dummy value, for example "<frozen>".  The privilege of
       not having a __file__ attribute at all is reserved for built-in


More information about the Python-checkins mailing list