Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
In the following MRE,code.co_firstlineno correctly returns 4, the first line number of the class definition, butgetsource(code) returns the content of the entire file:
importsysfrominspectimportgetsourceclassA:code=sys._getframe(0).f_codeprint(code.co_firstlineno)print(getsource(code))
This is becauseinspect.findsource uses a regex pattern that does not matchclass:
Line 1155 ina8e93d3
| pat=re.compile(r'^(\s*def\s)|(\s*async\s+def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)') |
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows