summaryrefslogtreecommitdiff
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
commitda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch)
tree74845e2dbd9521d9748b9c32f1922f4123083bf3 /Lib/traceback.py
parente3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff)
parent1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff)
downloadcpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz
Issue #29371: merge with 3.5
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index c5fd61716c..09bda717ad 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
@@ -487,10 +510,9 @@ class TracebackException:
self._load_lines()
@classmethod
- def from_exception(self, exc, *args, **kwargs):
+ def from_exception(cls, exc, *args, **kwargs):
"""Create a TracebackException from an exception."""
- return TracebackException(
- type(exc), exc, exc.__traceback__, *args, **kwargs)
+ return cls(type(exc), exc, exc.__traceback__, *args, **kwargs)
def _load_lines(self):
"""Private API. force all lines in the stack to be loaded."""