Fix specification error that makes it impossible for 'reload()' to work

correctly with PEP 302 module loaders.  See also SF#1029475, and:

http://mail.python.org/pipermail/python-dev/2004-September/048970.html
This commit is contained in:
Phillip J. Eby 2004-09-23 04:06:40 +00:00
parent 100532ac71
commit 9822ad205e
1 changed files with 11 additions and 5 deletions

View File

@ -240,16 +240,22 @@ Specification part 1: The Importer Protocol
The load_module() method has a few responsibilities that it must
fulfill *before* it runs any code:
- It must create the module object. From Python this can be done
- It must use the existing module object from sys.modules, if one
exists. (Otherwise, the reload() builtin will not work
correctly.)
- If a module object is not already present in sys.modules, the
loader must create a module object. From Python this can be done
via the new.module() function, the imp.new_module() function or
via the module type object; from C with the PyModule_New()
function or the PyImport_ModuleAdd() function. The latter also
does the following step:
- It must add the module to sys.modules. 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.
- It must add the module to sys.modules, if it was not already
present there. 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.
- The __file__ attribute must be set. This must be a string, but it
may be a dummy value, for example "<frozen>". The privilege of