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:
parent
100532ac71
commit
9822ad205e
16
pep-0302.txt
16
pep-0302.txt
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue