Message75952
This seems related to http://bugs.python.org/issue1218234 as well.
This is my first bug report. I hope I do this right.
I posted this to comp.lang.python and was directed here. Here is a
chopped paste of that post:
I am getting an error on line 510 of inspect.py:
504 if iscode(object):
505 if not hasattr(object, 'co_firstlineno'):
506 raise IOError('could not find function definition')
507 lnum = object.co_firstlineno - 1
508 pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
509 while lnum > 0:
510 if pat.match(lines[lnum]): break
511 lnum = lnum - 1
512 return lines, lnum
I finally figured out that there was a caching problem. The function I
passed was changed, but the code lines (strings) retrieved by
linecache.getlines() (on lines 464 and 466) didn't update with the new
module contents... To get around this, I invoke linecache.clearcache()...
linecache.clearcache()
lines, n = inspect.getsourcelines(fn)
While inspect uses the cached module to get the text, the line number
used to find the block of source lines is retrieved from the passed
object. So, if I pass a function which reports that it starts on line
50, but in the cache it starts on line 40, an error isn't raised but the
lines of code returned are wrong. The error only occurs when the line
number is higher than the number of lines in the cached module.
Cheers,
- Rafe |
|
Date |
User |
Action |
Args |
2008-11-17 07:58:27 | RafeSacks | set | recipients:
+ RafeSacks, gvanrossum, theller, exarkun, ndim |
2008-11-17 07:58:27 | RafeSacks | set | messageid: <1226908707.57.0.831193286573.issue1309567@psf.upfronthosting.co.za> |
2008-11-17 07:58:26 | RafeSacks | link | issue1309567 messages |
2008-11-17 07:58:24 | RafeSacks | create | |
|