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: linecache package handling
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.6
Status: closed Resolution: duplicate
Dependencies: Superseder: linecache module returns wrong results
View: 1309567
Assigned To: georg.brandl Nosy List: ajaksu2, georg.brandl, kevingoodsell, ndim
Priority: normal Keywords: patch

Created on 2007-07-15 22:40 by kevingoodsell, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit kevingoodsell, 2007-07-16 22:58 Patch for linecache handling of packages (Updated - comment typo fixed)
linecache.py_2008_07_04.patch kevingoodsell, 2008-07-05 05:58 New patch kevingoodsell, 2008-07-05 06:00 Test script for linecache
Messages (9)
msg52881 - (view) Author: Kevin Goodsell (kevingoodsell) Date: 2007-07-15 22:40
The linecache module does not handle packages at all (Guido mentions here that he wrote it before Python had packages:

This seems to cause problems with pdb and pydoc, as illustrated by this example:

$ mkdir pydoc_test
$ cd pydoc_test
$ echo "#" >
$ pydoc logging

This gives a traceback due to an out of range index, resulting essentially from ./ being confused with logging/ A line number from the latter is used as an index into a list of the lines from the former.

Patch attached, and a bit more explanation can be seen here:
msg52882 - (view) Author: Kevin Goodsell (kevingoodsell) Date: 2007-07-16 22:58
New patch upload, typo fix.
File Added:
msg69032 - (view) Author: Hans Ulrich Niedermann (ndim) Date: 2008-07-01 00:25
The patch does not fix the underlying problem which is not limited to
files named ''.
msg69035 - (view) Author: Hans Ulrich Niedermann (ndim) Date: 2008-07-01 00:28
The following issues appear to be the same bug to me:

and are, as of 2008-06-30, unfixed in both rel25-maint and trunk.
msg69272 - (view) Author: Kevin Goodsell (kevingoodsell) Date: 2008-07-05 05:58
Hans is right, that patch isn't very good. Here's a second pass. This
one avoids joining the file basename to sys.path components, which I'd
say is wrong since it strips (presumably relevant) leading path components.

A second part of this skips out early on absolute file names, which
prevents joining them with sys.path components also. As far as I can
tell this would cause no harm, but it's not useful either.
msg69273 - (view) Author: Kevin Goodsell (kevingoodsell) Date: 2008-07-05 06:00
Here's a small test script.
msg69279 - (view) Author: Hans Ulrich Niedermann (ndim) Date: 2008-07-05 12:37
Even with that patch, I'm still getting backtraces similar to this:

Traceback (most recent call last):
  File "/home/user/foo/src/foo", line 83, in <module>
  File "/home/uli/foo/src/foo", line 79, in foomain
  File "./foolib/", line 250, in cmdmain
  File "./foolib/", line 199, in main
  File "./foolib/", line 180, in __init__
  File "./foolib/", line 115, in __get__
AttributeError: property--48216a94

Looks like I should write a dozen test cases I can think of on my own. :)
msg86548 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-04-25 20:32
Test script works with patch from issue 1309567. Hans, do you have more
test cases?
msg87222 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-05 08:22
Setting #1309567 as superseder.
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45204
2009-05-05 08:22:17georg.brandlsetstatus: open -> closed
superseder: linecache module returns wrong results
messages: + msg87222

dependencies: - linecache module returns wrong results
resolution: duplicate
2009-04-25 20:32:06ajaksu2setversions: + Python 2.6, Python 3.0
nosy: + ajaksu2

messages: + msg86548

dependencies: + linecache module returns wrong results
type: behavior
2008-07-05 12:37:21ndimsetmessages: + msg69279
2008-07-05 09:49:01georg.brandlsetassignee: georg.brandl
nosy: + georg.brandl
2008-07-05 06:00:55kevingoodsellsetfiles: +
messages: + msg69273
2008-07-05 05:58:46kevingoodsellsetfiles: + linecache.py_2008_07_04.patch
messages: + msg69272
2008-07-01 00:28:27ndimsetmessages: + msg69035
2008-07-01 00:25:59ndimsetnosy: + ndim
messages: + msg69032
2007-07-15 22:40:12kevingoodsellcreate