This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pydoc -k IndexError on empty docstring
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
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 2022-04-11 14:58 by admin. This issue is now closed.

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>
  File "/usr/lib/python3.4/", line 2548, in cli
  File "/usr/lib/python3.4/", line 2080, in apropos
    ModuleScanner().run(callback, key, onerror=onerror)
  File "/usr/lib/python3.4/", 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
msg236119 - (view) Author: Roundup Robot (python-dev) (Python triager) 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)

New changeset 534b26837a13 by Benjamin Peterson in branch 'default':
merge 3.4 (#21548)
msg236261 - (view) Author: Roundup Robot (python-dev) (Python triager) 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
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65747
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