Closed
Description
Bug report
Bug description:
In the following MRE, code.co_firstlineno
correctly returns 4, the first line number of the class definition, but getsource(code)
returns the content of the entire file:
import sys
from inspect import getsource
class A:
code = sys._getframe(0).f_code
print(code.co_firstlineno)
print(getsource(code))
This is because inspect.findsource
uses a regex pattern that does not match class
:
Line 1155 in a8e93d3
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows