summaryrefslogtreecommitdiff
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2016-08-15 13:11:34 +1000
committerNick Coghlan <ncoghlan@gmail.com>2016-08-15 13:11:34 +1000
commitd00342347e467981b52368235b99a22dc264dab1 (patch)
treee7ea356a2c4e93f592fd7f3e52e12dfeccfaf13e /Lib/traceback.py
parentd61a2e75b5218f0f89b4f623713004edb9512180 (diff)
downloadcpython-git-d00342347e467981b52368235b99a22dc264dab1.tar.gz
Issue #26823: Abbreviate recursive tracebacks
Large sections of repeated lines in tracebacks are now abbreviated as "[Previous line repeated {count} more times]" by both the traceback module and the builtin traceback rendering. Patch by Emanuel Barry.
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 3b46c0b050..a1cb5fb1ef 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -385,9 +385,30 @@ class StackSummary(list):
resulting list corresponds to a single frame from the stack.
Each string ends in a newline; the strings may contain internal
newlines as well, for those items with source text lines.
+
+ For long sequences of the same frame and line, the first few
+ repetitions are shown, followed by a summary line stating the exact
+ number of further repetitions.
"""
result = []
+ last_file = None
+ last_line = None
+ last_name = None
+ count = 0
for frame in self:
+ if (last_file is not None and last_file == frame.filename and
+ last_line is not None and last_line == frame.lineno and
+ last_name is not None and last_name == frame.name):
+ count += 1
+ else:
+ if count > 3:
+ result.append(f' [Previous line repeated {count-3} more times]\n')
+ last_file = frame.filename
+ last_line = frame.lineno
+ last_name = frame.name
+ count = 0
+ if count >= 3:
+ continue
row = []
row.append(' File "{}", line {}, in {}\n'.format(
frame.filename, frame.lineno, frame.name))
@@ -397,6 +418,8 @@ class StackSummary(list):
for name, value in sorted(frame.locals.items()):
row.append(' {name} = {value}\n'.format(name=name, value=value))
result.append(''.join(row))
+ if count > 3:
+ result.append(f' [Previous line repeated {count-3} more times]\n')
return result