classification
Title: pydoc -k IndexError on empty docstring
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dima.Tisnek, Yuyang.Guo, benjamin.peterson, berker.peksag, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2014-05-21 08:43 by Dima.Tisnek, last changed 2015-02-20 10:10 by berker.peksag. This issue is now closed.

Files
File name Uploaded Description Edit
issue21548.patch Yuyang.Guo, 2014-06-07 18:13 review
issue21548.diff berker.peksag, 2015-01-25 00:30 review
Messages (8)
msg218865 - (view) Author: Dima Tisnek (Dima.Tisnek) Date: 2014-05-21 08:43
While trying to track down another bug, I disabled some packages:

[dima@bmg tmp]$ chmod a-x /usr/lib/python3.4/site-packages/speechd*

Then ran pydoc -k:

[dima@bmg tmp]$ pydoc3.4 -k n688954789
Traceback (most recent call last):
  File "/usr/bin/pydoc3.4", line 5, in <module>
    pydoc.cli()
  File "/usr/lib/python3.4/pydoc.py", line 2548, in cli
    apropos(val)
  File "/usr/lib/python3.4/pydoc.py", line 2080, in apropos
    ModuleScanner().run(callback, key, onerror=onerror)
  File "/usr/lib/python3.4/pydoc.py", line 2061, in run
    desc = (module.__doc__ or '').splitlines()[0]
IndexError: list index out of range

Clearly "".splitlines() is always empty; missing doc is not handled correctly.
msg218998 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-23 21:07
Replacing 2061 with the following should work for all versions.
desc = module.__doc__.splitlines()[0] if module.__doc__ else ''
msg219956 - (view) Author: Yuyang Guo (Yuyang.Guo) * Date: 2014-06-07 18:13
Made change based on Terry J. Reedy's suggestion
msg219971 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-06-07 20:13
Thanks for the patch! It looks like the "synopsis" function also has this bug. Could you fix that, too?
msg234641 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-01-25 00:30
Here's a patch with tests.
msg236117 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-16 22:44
LGTM.
msg236119 - (view) Author: Roundup Robot (python-dev) Date: 2015-02-17 00:45
New changeset 9436f43b6df2 by Benjamin Peterson in branch '3.4':
fix pydoc.apropos and pydoc.synopsis on modules with empty docstrings (#21548)
https://hg.python.org/cpython/rev/9436f43b6df2

New changeset 534b26837a13 by Benjamin Peterson in branch 'default':
merge 3.4 (#21548)
https://hg.python.org/cpython/rev/534b26837a13
msg236261 - (view) Author: Roundup Robot (python-dev) Date: 2015-02-20 10:09
New changeset 43641e03692a by Berker Peksag in branch '2.7':
Issue #21548: Fix pydoc.synopsis() and pydoc.apropos() on modules with empty
https://hg.python.org/cpython/rev/43641e03692a
History
Date User Action Args
2015-02-20 10:10:26berker.peksagsetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2015-02-20 10:09:38python-devsetmessages: + msg236261
2015-02-17 00:45:49python-devsetnosy: + python-dev
messages: + msg236119
2015-02-16 22:44:14serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg236117
stage: patch review -> commit review
2015-01-25 00:30:55berker.peksagsetfiles: + issue21548.diff

nosy: + berker.peksag
messages: + msg234641

stage: patch review
2014-06-07 20:13:13benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg219971
2014-06-07 18:13:15Yuyang.Guosetfiles: + issue21548.patch

nosy: + Yuyang.Guo
messages: + msg219956

keywords: + patch
2014-06-02 00:38:33r.david.murraysetkeywords: + easy
2014-05-23 21:07:00terry.reedysetversions: + Python 2.7, Python 3.5
nosy: + terry.reedy

messages: + msg218998

type: behavior
2014-05-21 08:43:03Dima.Tisnekcreate