From 91cb298f811961277fd4cc4a32211899d48bedcb Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 24 Aug 2018 07:18:00 -0700 Subject: bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) --- Lib/inspect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Lib/inspect.py') diff --git a/Lib/inspect.py b/Lib/inspect.py index 717518614f..e799a83a74 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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 == "")): return lines, 0 else: return getblock(lines[lnum:]), lnum + 1 -- cgit v1.2.1