We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 97ffaf0 commit 05abdb9Copy full SHA for 05abdb9
1 file changed
Lib/inspect.py
@@ -1002,6 +1002,15 @@ def findsource(object):
1002
lnum = object.co_firstlineno - 1
1003
if lnum >= len(lines):
1004
raise OSError('lineno is out of bounds')
1005
+ pat = re.compile(r'^(\s*def\s)|(\s*class\s)|(\s*async\s+def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
1006
+ while lnum > 0:
1007
+ try:
1008
+ line = lines[lnum]
1009
+ except IndexError:
1010
+ raise OSError('lineno is out of bounds')
1011
+ if pat.match(line):
1012
+ break
1013
+ lnum = lnum - 1
1014
return lines, lnum
1015
raise OSError('could not find code object')
1016
0 commit comments