[Python-checkins] r53034 - sandbox/trunk/import_in_py/importer.py
brett.cannon
python-checkins at python.org
Thu Dec 14 20:43:33 CET 2006
Author: brett.cannon
Date: Thu Dec 14 20:43:32 2006
New Revision: 53034
Modified:
sandbox/trunk/import_in_py/importer.py
Log:
Pull out implementation notes out of the module docstring and move to the
Google Doc.
Also change exception messages to match.
Modified: sandbox/trunk/import_in_py/importer.py
==============================================================================
--- sandbox/trunk/import_in_py/importer.py (original)
+++ sandbox/trunk/import_in_py/importer.py Thu Dec 14 20:43:32 2006
@@ -1,115 +1,22 @@
"""Re-implementation of import machinery in Python source code.
+XXX See http://docs.google.com/View?docid=dg7fctr4_4d8tdbq on current status.
+
References on import:
* Language reference
- http://docs.python.org/ref/import.html
+ http://docs.python.org/ref/import.html
* __import__ function
- http://docs.python.org/lib/built-in-funcs.html
+ http://docs.python.org/lib/built-in-funcs.html
* Packages
- http://www.python.org/doc/essays/packages.html
+ http://www.python.org/doc/essays/packages.html
* PEP 235: Import on Case-Insensitive Platforms
- http://www.python.org/dev/peps/pep-0235
+ http://www.python.org/dev/peps/pep-0235
* PEP 275: Import Modules from Zip Archives
- http://www.python.org/dev/peps/pep-0273
+ http://www.python.org/dev/peps/pep-0273
* PEP 302: New Import Hooks
- http://www.python.org/dev/peps/pep-0302/
+ http://www.python.org/dev/peps/pep-0302/
* PEP 328: Imports: Multi-line and Absolute/Relative
- http://www.python.org/dev/peps/pep-0328
-
-Clarifications
-==============
-* Raise ImportError when load_module() fails to load a module without
- raising an exception.
-* Is module returned by load_module() actually used for anything?
- + Can always just return from sys.modules.
-* PEP 302 does not mention if __name__ must be set before any code is executed
- or not.
-
-
-XXX See http://docs.google.com/View?docid=dg7fctr4_4d8tdbq on current status.
-
-
-Things to be exposed at the Python level
-========================================
-* Python/marshal.c:r_long()/w_long()
- + Using own version temporarily.
-
-
-Py3k
-====
-Improvements
-------------
-* Have a meta_path entry for checking sys.modules to remove need for
- loaders or __import__ to do it.
-* Put importer objects directly into sys.path to remove need for
- sys.path_importer_cache. Could leave string entries on sys.path that do
- not have an importer so they can be re-checked the next time a new import
- is attempted.
- + If __import__ handles sys.modules then the impact from having to
- recheck sys.path entries that lack an importer is minimized as it is
- only on imports that have not been handled before.
- - This has the drawback of making it more difficult for
- non-standard modules to be put into sys.modules. Could go other
- way and hyper-generalize by having a meta_path importer that
- returns entries in sys.path.
-* Loaders don't have to return the loaded module.
- + Importing the module being imported in a circular import dependency
- requires that module added to sys.modules stay consistent from the
- point it is added to initialization anyway.
- + Can get the module the loader was supposed to handle directly out of
- sys.modules.
-* Remove any idea of a default importer.
- + Removes support for None entries from sys.path_importer_cache.
- + Rely on default importers being in sys.path_hooks or sys.meta_path.
-* Remove implicit relative import in packages when dealing with '*'.
- + Would only require adding an import line for each item in __all__ that is
- a module.
- + Explicit is better than implicit.
- + Can't entire remove without requiring ``import pkg.module as module``
- on imports instead of ``from pkg import module``.
-* Any way to replace imp.acquire_lock()/release_lock() with a context manager instead?
-
-Rejected Ideas
---------------
-* Passing in new module to loaders
- Creating a new module is minimal and loader might want to use a different
- type of object.
-
-
-Use Cases
-=========
-PTL
----
-* Use filesystem importer and loader.
-* Subclass PyPycHandler
- + Set source_handles to '.ptl' and bytecode to '.ptlc'.
- + code_from_source()
- - Handle transforming to pure Python code here.
-
-sqlite3
--------
-+ DB
- - Module name.
- - Source code.
- - Marshalled code of the source.
- * Set to NULL when source code is modified, which removes need of
- storing the bytecode's timestamp.
- - Magic number for bytecode.
- - Anything about handling packages?
-+ Importer
- - Query DB to see if module is listed.
- - Whether it is in bytecode or source form is irrelevant.
-+ Loader
- - See if bytecode is in DB; if so then have that used, otherwise source.
- - Implement API needed by PyPycHandler for free bytecode recreation.
-+ Use PyPycHandler.
-
-zip importer
-------------
-+ New importer
-+ New loader
- - Have write_data be a no-op.
-+ Reuse PyPycHandler.
+ http://www.python.org/dev/peps/pep-0328
"""
from __future__ import with_statement
@@ -587,7 +494,7 @@
if loader:
return loader
else:
- raise ImportError("%s not found on sys.meta_path" % name)
+ raise ImportError("No module named %s" % name)
def sys_path_importer(self, path_entry):
"""Return the importer for the specified path.
@@ -647,7 +554,7 @@
if loader:
return loader
else:
- raise ImportError("%s not found on sys.path" % name)
+ raise ImportError("No module found named %s" % name)
def import_module(self, name, path=None):
"""Import the specified module with no handling of parent modules.
More information about the Python-checkins
mailing list