[issue9284] inspect.findsource() cannot find source for doctest code

Dirkjan Ochtman report at bugs.python.org
Sat Jul 17 16:24:47 CEST 2010


Dirkjan Ochtman <dirkjan at ochtman.nl> added the comment:

Here's a test case that doesn't require doctest trickery:

import inspect, linecache
fn, source = '<test>', 'def x(): pass\n'
getlines = linecache.getlines
def monkey(filename, module_globals=None):
     if filename == fn:
         return source.splitlines(True)
     else:
         return getlines(filename, module_globals)
linecache.getlines = monkey
exec compile(source, fn, 'single') in globals()
inspect.getsource(x)

----------

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


More information about the Python-bugs-list mailing list