summaryrefslogtreecommitdiff
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorVladimir Matveev <v2matveev@outlook.com>2018-08-24 07:18:00 -0700
committerTal Einat <taleinat+github@gmail.com>2018-08-24 17:18:00 +0300
commit91cb298f811961277fd4cc4a32211899d48bedcb (patch)
tree6b833e01b19fdae681b767cc44f4b8d3e676e88a /Lib/inspect.py
parent075b3c325913475be16650f7cb2a99f3136623b9 (diff)
downloadcpython-git-91cb298f811961277fd4cc4a32211899d48bedcb.tar.gz
bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py7
1 files changed, 6 insertions, 1 deletions
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 == "<module>")):
return lines, 0
else:
return getblock(lines[lnum:]), lnum + 1