[issue24485] Function source inspection fails on closures

Terry J. Reedy report at bugs.python.org
Fri Jun 26 22:46:38 CEST 2015


Terry J. Reedy added the comment:

The test suite must lack, and therefore needs, a simple testcase as in test.py.

In 3.4 and 3.5, getsource() joins the list of lines returned by getsourcelines().  In both versions, getsourcelines uses findsource(), which seems to be unchanged.  In 3.5, the output of findsource for code, function, and method objects is postprocessed by _line_number_helper(code_object).  The bug applies to methods also.

class C:
    def outer():
        def inner():
            inner1
from inspect import getsource
print(getsource(C.outer))

omits 'inner1', but getsource(C) does not.  I believe the regression is due to ac86e5b2d45b in #21217.  (At first glance, it would seem that the fixup in _line_number_helper should be in the code object part of findsource itself.)  I requested on that issue that the authors take a look at this.

----------
stage: needs patch -> test needed

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


More information about the Python-bugs-list mailing list