pydoc logging traceback

Bug #70902 reported by Tristan Hill
4
Affects Status Importance Assigned to Milestone
Python
Fix Released
Unknown
python-defaults (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: python

$ pydoc logging
Traceback (most recent call last):
  File "/usr/bin/pydoc", line 5, in ?
    pydoc.cli()
  File "/usr/lib/python2.4/pydoc.py", line 2247, in cli
    help.help(arg)
  File "/usr/lib/python2.4/pydoc.py", line 1698, in help
    elif request: doc(request, 'Help on %s:')
  File "/usr/lib/python2.4/pydoc.py", line 1483, in doc
    pager(title % desc + '\n\n' + text.document(object, name))
  File "/usr/lib/python2.4/pydoc.py", line 303, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/usr/lib/python2.4/pydoc.py", line 1077, in docmodule
    contents.append(self.document(value, key, name))
  File "/usr/lib/python2.4/pydoc.py", line 304, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "/usr/lib/python2.4/pydoc.py", line 1201, in docclass
    lambda t: t[1] == 'method')
  File "/usr/lib/python2.4/pydoc.py", line 1151, in spill
    name, mod, object))
  File "/usr/lib/python2.4/pydoc.py", line 305, in document
    if inspect.isroutine(object): return self.docroutine(*args)
  File "/usr/lib/python2.4/pydoc.py", line 1262, in docroutine
    doc = getdoc(object) or ''
  File "/usr/lib/python2.4/pydoc.py", line 75, in getdoc
    result = inspect.getdoc(object) or inspect.getcomments(object)
  File "/usr/lib/python2.4/inspect.py", line 448, in getcomments
    lines, lnum = findsource(object)
  File "/usr/lib/python2.4/inspect.py", line 437, in findsource
    if pat.match(lines[lnum]): break
IndexError: list index out of range
$ dpkg -s python | grep Ver
Version: 2.4.3-11ubuntu3

Tags: upstream

Related branches

Revision history for this message
Kevin Goodsell (kevin-goodsell) wrote :

I can confirm that this still exists in python 2.5 in feisty. In order to repro, please do the following:

$ mkdir pydoc_test
$ cd pydoc_test
$ echo "#" > __init__.py
$ pydoc logging

Revision history for this message
Kevin Goodsell (kevin-goodsell) wrote :

This appears to be a long-standing problem in the standard linecache module. It doesn't handle packages correctly. In the updatecache function, line 82 does this:

basename = os.path.split(filename)[1]

In my example, filename is 'logging/__init__.py', so basename becomes '__init__.py'. Later, updatecache iterates through sys.path joining basename to each entry, calls os.stat on the result to see if it is valid, and accepts the first valid file it finds. sys.path contains '.', so the first valid file is './__init__.py' -- obviously not the source file it was looking for.

The attached patch checks for basename == '__init__.py' and uses the passed-in filename instead. For a package, that should give the relative path to the __init__.py file from a location is sys.path.

Matthias Klose (doko)
Changed in python-defaults:
importance: Undecided → Low
status: New → Confirmed
importance: Low → Medium
Revision history for this message
Steve Langasek (vorlon) wrote :

this bug was resolved in python2.5 2.5.1-5ubuntu1:

python2.5 (2.5.1-5ubuntu1) gutsy; urgency=low

  * Fix handling of packages in linecache.py (Kevin Goodsell). LP: #70902.
  * Bump debhelper to v5.

 -- Matthias Klose <email address hidden> Fri, 17 Aug 2007 11:49:16 +0200

Changed in python-defaults:
status: Confirmed → Fix Released
Changed in python:
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.