- some whitespace normalization (two spaces after sentence endings; yuck! ;-)
- minor edits - added short Forward Compatibility section - added comment about the Quixote/PTL use case to Open Issues
This commit is contained in:
parent
bc79aa595e
commit
6d66240b0c
37
pep-0302.txt
37
pep-0302.txt
|
@ -271,8 +271,8 @@ Specification part 1: The Importer Protocol
|
|||
with an importer.
|
||||
|
||||
If the module is a Python module (as opposed to a built-in module or
|
||||
an dynamically loaded extension), it should execute the module's
|
||||
code in the module's global name space (module.__dict__).
|
||||
a dynamically loaded extension), it should execute the module's code
|
||||
in the module's global name space (module.__dict__).
|
||||
|
||||
Here is a minimal pattern for a load_module() method:
|
||||
|
||||
|
@ -347,9 +347,9 @@ Packages and the role of __path__
|
|||
as path items are also allowed (yet, are discouraged for the same
|
||||
reasons as they are discouraged on sys.path, at least for general
|
||||
purpose code). Meta importers don't necessarily use sys.path at all
|
||||
to do their work and therefore may also ignore the value of
|
||||
pkg.__path__. In this case it is still advised to set it to list,
|
||||
which can be empty.
|
||||
to do their work and may therefore ignore the value of pkg.__path__.
|
||||
In this case it is still advised to set it to list, which can be
|
||||
empty.
|
||||
|
||||
|
||||
Optional Extensions to the Importer Protocol
|
||||
|
@ -427,9 +427,9 @@ Integration with the 'imp' module
|
|||
existing imp.find_module() and imp.load_module() calls changes from:
|
||||
"they expose the built-in import mechanism" to "they expose the
|
||||
basic *unhooked* built-in import mechanism". They simply won't
|
||||
invoke any import hooks. A new imp module function is proposed
|
||||
under the name "find_module2", with is used like the following
|
||||
pattern:
|
||||
invoke any import hooks. A new imp module function is proposed (but
|
||||
not yet implemented) under the name "find_module2", which is used as
|
||||
in the following pattern:
|
||||
|
||||
loader = imp.find_module2(fullname, path)
|
||||
if loader is not None:
|
||||
|
@ -445,6 +445,14 @@ Integration with the 'imp' module
|
|||
ImpWrapper class) included with the patch.
|
||||
|
||||
|
||||
Forward Compatibility
|
||||
|
||||
Existing __import__ hooks will not invoke new-style hooks by magic,
|
||||
unless they call the original __import__ function as a fallback. For
|
||||
example, ihooks.py, iu.py and imputil.py are in this sense not
|
||||
forward compatible with this PEP.
|
||||
|
||||
|
||||
Open Issues
|
||||
|
||||
The new hook method allows for the possibility of objects other than
|
||||
|
@ -510,6 +518,16 @@ Open Issues
|
|||
get_data() method. However, it's a bit unclear which object should
|
||||
implement list_modules(): the importer or the loader or both?
|
||||
|
||||
This PEP is biased towards loading modules from alternative places:
|
||||
it currently doesn't offer dedicated solutions for loading modules
|
||||
from alternative file formats or with alternative compilers. In
|
||||
contrast, the ihooks module from the standard library does have a
|
||||
fairly straightforward way to do this. The Quixote project [8] uses
|
||||
this technique to import PTL files as if they are ordinary Python
|
||||
modules. To do the same with the new hooks would either mean to add
|
||||
a new module implementing a subset of ihooks as a new-style
|
||||
importer, or add a hookable built-in path importer object.
|
||||
|
||||
|
||||
Implementation
|
||||
|
||||
|
@ -542,6 +560,9 @@ References and Footnotes
|
|||
come from the actual parent module or be supplied by
|
||||
imp.find_module() or the proposed imp.find_module2() function.
|
||||
|
||||
[8] Quixote, a framework for developing Web applications
|
||||
http://www.mems-exchange.org/software/quixote/
|
||||
|
||||
|
||||
Copyright
|
||||
|
||||
|
|
Loading…
Reference in New Issue