[New-bugs-announce] [issue5742] inspect.findsource() should look only for sources

Dmitry Vasiliev report at bugs.python.org
Sun Apr 12 20:29:13 CEST 2009


New submission from Dmitry Vasiliev <dima at hlabs.spb.ru>:

Currently help(zlib) gives the following traceback:

Python 3.1a2+ (py3k:71538M, Apr 12 2009, 21:54:44) 
>>> import zlib
>>> help(zlib)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Lib/site.py", line 429, in __call__
    return pydoc.help(*args, **kwds)
  File "Lib/pydoc.py", line 1709, in __call__
    self.help(request)
  File "Lib/pydoc.py", line 1755, in help
    else: doc(request, 'Help on %s:')
  File "Lib/pydoc.py", line 1505, in doc
    pager(render_doc(thing, title, forceload))
  File "Lib/pydoc.py", line 1500, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "Lib/pydoc.py", line 320, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "Lib/pydoc.py", line 1086, in docmodule
    contents.append(self.document(value, key, name))
  File "Lib/pydoc.py", line 321, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "Lib/pydoc.py", line 1131, in docclass
    doc = getdoc(object)
  File "Lib/pydoc.py", line 81, in getdoc
    result = inspect.getdoc(object) or inspect.getcomments(object)
  File "Lib/inspect.py", line 581, in getcomments
    lines, lnum = findsource(object)
  File "Lib/inspect.py", line 524, in findsource
    lines = linecache.getlines(file, module.__dict__)
  File "Lib/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "Lib/linecache.py", line 127, in updatecache
    lines = fp.readlines()
  File "Lib/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 41-42:
invalid data

After some investigation I've found that inspect.findsource() try to use
getfile() if getsourcefile() fail to find the source file. I don't see
why findsource() should return lines from a compiled file so I think
it's a bug. The same bug also exists in Python 2.7 although it's not so
critical. I've attached the patch which fixes the problem.

----------
components: Library (Lib)
files: inspect.patch
keywords: patch
messages: 85916
nosy: hdima
severity: normal
status: open
title: inspect.findsource() should look only for sources
type: crash
versions: Python 3.1
Added file: http://bugs.python.org/file13678/inspect.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5742>
_______________________________________


More information about the New-bugs-announce mailing list