classification
Title: pydoc help("modules keyword") is failing when a module throws an exception at the import time
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Improve the robustness of "pydoc -k" in the face of broken modules
View: 7425
Assigned To: Nosy List: Christian.S..Perone, ned.deily
Priority: normal Keywords:

Created on 2011-09-05 01:15 by Christian.S..Perone, last changed 2011-09-05 01:31 by ned.deily. This issue is now closed.

Messages (2)
msg143502 - (view) Author: Christian S. Perone (Christian.S..Perone) Date: 2011-09-05 01:15
Pydoc is failing when running the ModuleScanner().run() when you execute:

help("modules keyword")

... if some module throws an exception at the import time.
See this example:

>>> help("modules convolve")

Here is a list of matching modules.  Enter any module name to get more help.

numpy.numarray.convolve
scipy.fftpack.convolve
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site.py", line 467, in __call__
    return pydoc.help(*args, **kwds)
  File "C:\Python27\lib\pydoc.py", line 1727, in __call__
    self.help(request)
  File "C:\Python27\lib\pydoc.py", line 1768, in help
    self.listmodules(split(request)[1])
  File "C:\Python27\lib\pydoc.py", line 1873, in listmodules
    apropos(key)
  File "C:\Python27\lib\pydoc.py", line 1975, in apropos
    ModuleScanner().run(callback, key)
  File "C:\Python27\lib\pydoc.py", line 1938, in run
    for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
  File "C:\Python27\lib\pkgutil.py", line 125, in walk_packages
    for item in walk_packages(path, name+'.', onerror):
  File "C:\Python27\lib\pkgutil.py", line 125, in walk_packages
    for item in walk_packages(path, name+'.', onerror):
  File "C:\Python27\lib\pkgutil.py", line 125, in walk_packages
    for item in walk_packages(path, name+'.', onerror):
  File "C:\Python27\lib\pkgutil.py", line 125, in walk_packages
    for item in walk_packages(path, name+'.', onerror):
  File "C:\Python27\lib\pkgutil.py", line 110, in walk_packages
    __import__(name)
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\pubsub\core\arg1\__init__.py", line 16, in <module>
    raise RuntimeError(msg)
RuntimeError: Should not import this directly, used by pubsub.core if applicable

After suppressing the exception by changing the "apropos()" method inside the pydoc.py:

Line:
ModuleScanner().run(callback, key)

To:
ModuleScanner().run(callback, key, onerror=lambda error: error)

The problem is fixed, but I really don't know if this is the best way to suppress this and if we should suppress these exceptions, I think that as the intent of the help("modules keyword") is to find things with the keyword in the name, we shouldn't let the exception be propagated to the user.
msg143504 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-09-05 01:31
Thanks for the suggested fix.  It looks like the problem and fix have already been documented in Issue7425.  Merging this into the existing issue.
History
Date User Action Args
2011-09-05 01:31:25ned.deilysetstatus: open -> closed

superseder: Improve the robustness of "pydoc -k" in the face of broken modules

nosy: + ned.deily
messages: + msg143504
resolution: duplicate
stage: resolved
2011-09-05 01:15:57Christian.S..Peronecreate