diff options
author | Phillip J. Eby <pje@telecommunity.com> | 2006-07-28 21:12:07 +0000 |
---|---|---|
committer | Phillip J. Eby <pje@telecommunity.com> | 2006-07-28 21:12:07 +0000 |
commit | f7575d0cb7a10b252cc1e05a1d24facc2294a195 (patch) | |
tree | 28146830a0734bcbcb4e72ff634113f110e386bc /Doc/lib | |
parent | 944f3b6ecba741b54fed1190980fba1272568ebe (diff) | |
download | cpython-git-f7575d0cb7a10b252cc1e05a1d24facc2294a195.tar.gz |
Bug #1529871: The speed enhancement patch #921466 broke Python's compliance
with PEP 302. This was fixed by adding an ``imp.NullImporter`` type that is
used in ``sys.path_importer_cache`` to cache non-directory paths and avoid
excessive filesystem operations during imports.
Diffstat (limited to 'Doc/lib')
-rw-r--r-- | Doc/lib/libimp.tex | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Doc/lib/libimp.tex b/Doc/lib/libimp.tex index e0a775cad1..598d351827 100644 --- a/Doc/lib/libimp.tex +++ b/Doc/lib/libimp.tex @@ -232,6 +232,24 @@ properly matching byte-compiled file (with suffix \file{.pyc} or source file. \end{funcdesc} +\begin{classdesc}{NullImporter}{path_string} +The \class{NullImporter} type is a \pep{302} import hook that handles +non-directory path strings by failing to find any modules. Calling this +type with an existing directory or empty string raises +\exception{ImportError}. Otherwise, a \class{NullImporter} instance is +returned. + +Python adds instances of this type to \code{sys.path_importer_cache} for +any path entries that are not directories and are not handled by any other +path hooks on \code{sys.path_hooks}. Instances have only one method: + +\begin{methoddesc}{find_module}{fullname \optional{, path}} +This method always returns \code{None}, indicating that the requested +module could not be found. +\end{methoddesc} + +\versionadded{2.5} +\end{classdesc} \subsection{Examples} \label{examples-imp} @@ -257,7 +275,7 @@ def __import__(name, globals=None, locals=None, fromlist=None): # there's a problem we can't handle -- let the caller handle it. fp, pathname, description = imp.find_module(name) - + try: return imp.load_module(name, fp, pathname, description) finally: |