bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864)

This commit is contained in:
Vladimir Matveev 2018-08-24 07:18:00 -07:00 committed by Tal Einat
parent 075b3c3259
commit 91cb298f81
4 changed files with 26 additions and 3 deletions

View file

@ -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