[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

Karthikeyan Singaravelan report at bugs.python.org
Sat Nov 3 14:53:35 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

Thanks Serhiy for the details. I think there are also less tests for inspect.findsource with respect to classes though it's more robust than the regex approach. Thus there might be different effects which are correct now or selects an alternate candidate as you have mentioned. I think this is worth adding a test case once the behavior is finalized. 

On a general note I am curious is there any patch to add line number directly to the class as an attribute? I think inspect module uses object.co_firstlineno where object is a code object and works for function object. Is there any technical difficulty in this? I searched the mailing list and PEPs but couldn't come across anything. Also there are couple of issues around showing source from REPL where it's not saved to the file issue33826, issue12920.

There is one more frame pointer issue that is not working with class objects with a PR that fixes some more issues in findsource with respect to classes : issue35101.


Thanks

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35113>
_______________________________________


More information about the Python-bugs-list mailing list