New submission from Dirkjan Ochtman <dirk...@ochtman.nl>:

The fix for issue4050 broke some of my doctests. Minimal test:

import doctest, inspect
def test():
    '''
    >>> def x(): pass
    >>> inspect.getsource(x)
    'def x(): pass\\n'
    '''
doctest.run_docstring_examples(test, globals())

This works in 2.6, but not in 2.7. Reason is that inspect.getsourcefile() finds 
the fake filename '<docTest NoName[0]>', 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[0] + f[-1] == '<>').

----------
components: Library (Lib)
messages: 110551
nosy: ajaksu2, brodie, djc, pitrou, r.david.murray
priority: normal
severity: normal
stage: needs patch
status: open
title: inspect.findsource() cannot find source for doctest code
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9284>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to