[New-bugs-announce] [issue4050] inspect.findsource() returns binary data for shared library modules

Brodie Rao report at bugs.python.org
Mon Oct 6 05:20:46 CEST 2008

New submission from Brodie Rao <junk at dackz.net>:

Calling inspect.findsource() on a module whose __file__ attribute points 
to a shared library causes findsource() to return the binary's data:

>>> import time
>>> time.__file__
>>> import inspect
>>> inspect.findsource(time)

It should raise an error saying it can't retrieve the source. It doesn't 
do this because when it tries to find the source file it calls both 
getsourcefile() - and getfile() when that fails. It should call only 
getsourcefile() - which checks to see if __file__ points to a binary - 
and if the result is None, raise an error.

I'm attaching a patch against trunk that fixes this. The issue affects 
3.0, 2.6, 2.5, and probably previous versions.

components: Library (Lib)
files: inspect-findsource-binary.diff
keywords: patch
messages: 74358
nosy: brodierao
severity: normal
status: open
title: inspect.findsource() returns binary data for shared library modules
type: behavior
versions: Python 2.5, Python 2.6, Python 3.0
Added file: http://bugs.python.org/file11706/inspect-findsource-binary.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list