[issue9284] inspect.findsource() cannot find source for doctest code
report at bugs.python.org
Sat Jul 17 15:16:57 CEST 2010
New submission from Dirkjan Ochtman <dirkjan at ochtman.nl>:
The fix for issue4050 broke some of my doctests. Minimal test:
import doctest, inspect
>>> def x(): pass
'def x(): pass\\n'
This works in 2.6, but not in 2.7. Reason is that inspect.getsourcefile() finds the fake filename '<docTest NoName>', which it doesn't understand. In 2.6, inspect.getmodule() is also tried, which first looks at obj.__module__, and the filename can be derived from that. I suggest that inspect.getsourcefile() grows some code to use this trick if the filename seems fake (f + f[-1] == '<>').
components: Library (Lib)
nosy: ajaksu2, brodie, djc, pitrou, r.david.murray
stage: needs patch
title: inspect.findsource() cannot find source for doctest code
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list