mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864)
This commit is contained in:
parent
075b3c3259
commit
91cb298f81
4 changed files with 26 additions and 3 deletions
|
@ -954,7 +954,12 @@ def getsourcelines(object):
|
|||
object = unwrap(object)
|
||||
lines, lnum = findsource(object)
|
||||
|
||||
if ismodule(object):
|
||||
if istraceback(object):
|
||||
object = object.tb_frame
|
||||
|
||||
# for module or frame that corresponds to module, return all source lines
|
||||
if (ismodule(object) or
|
||||
(isframe(object) and object.f_code.co_name == "<module>")):
|
||||
return lines, 0
|
||||
else:
|
||||
return getblock(lines[lnum:]), lnum + 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue