summaryrefslogtreecommitdiff
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorPhillip J. Eby <pje@telecommunity.com>2006-07-26 19:48:27 +0000
committerPhillip J. Eby <pje@telecommunity.com>2006-07-26 19:48:27 +0000
commiteb26ea3f83a0ea729eaf4bc2a44279013effd21a (patch)
tree5c4dd4a116679c2f9104afc4dc9f4f0c23fa13f7 /Lib/pkgutil.py
parentab260049238fecff65da6af508c804f5e8a092de (diff)
downloadcpython-git-eb26ea3f83a0ea729eaf4bc2a44279013effd21a.tar.gz
Allow the 'onerror' argument to walk_packages() to catch any Exception, not
just ImportError. This allows documentation tools to better skip unimportable packages.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index e138849de6..02497d7af7 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -83,13 +83,18 @@ def walk_packages(path=None, prefix='', onerror=None):
attribute to find submodules.
'onerror' is a function which gets called with one argument (the
- name of the package which was being imported) if an ImportError
- occurs trying to import a package. By default the ImportError is
- caught and ignored.
+ name of the package which was being imported) if any exception
+ occurs while trying to import a package. If no onerror function is
+ supplied, ImportErrors are caught and ignored, while all other
+ exceptions are propagated, terminating the search.
Examples:
- walk_packages() : list all modules python can access
- walk_packages(ctypes.__path__, ctypes.__name__+'.') : list all submodules of ctypes
+
+ # list all modules python can access
+ walk_packages()
+
+ # list all submodules of ctypes
+ walk_packages(ctypes.__path__, ctypes.__name__+'.')
"""
def seen(p, m={}):
@@ -106,6 +111,11 @@ def walk_packages(path=None, prefix='', onerror=None):
except ImportError:
if onerror is not None:
onerror(name)
+ except Exception:
+ if onerror is not None:
+ onerror(name)
+ else:
+ raise
else:
path = getattr(sys.modules[name], '__path__', None) or []