From 051b9818671625d125dee8198e0d2af5ad4c85b8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 16 Dec 2020 22:38:32 +0100 Subject: bpo-37961: Fix regression in tracemalloc.Traceback.__repr__ (GH-23805) Regression in 8d59eb1b66c51b2b918da9881c57d07d08df43b7. --- Lib/test/test_tracemalloc.py | 20 ++++++++++++++++++++ Lib/tracemalloc.py | 2 +- .../Library/2020-12-16-16-16-33.bpo-37961.jrESEq.rst | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2020-12-16-16-16-33.bpo-37961.jrESEq.rst diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py index a0037f8..5566567 100644 --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -85,6 +85,25 @@ def traceback_filename(filename): return traceback_lineno(filename, 0) +class TestTraceback(unittest.TestCase): + def test_repr(self): + def get_repr(*args) -> str: + return repr(tracemalloc.Traceback(*args)) + + self.assertEqual(get_repr(()), "") + self.assertEqual(get_repr((), 0), "") + + frames = (("f1", 1), ("f2", 2)) + exp_repr_frames = ( + "(," + " )" + ) + self.assertEqual(get_repr(frames), + f"") + self.assertEqual(get_repr(frames, 2), + f"") + + class TestTracemallocEnabled(unittest.TestCase): def setUp(self): if tracemalloc.is_tracing(): @@ -1065,6 +1084,7 @@ class TestCAPI(unittest.TestCase): def test_main(): support.run_unittest( + TestTraceback, TestTracemallocEnabled, TestSnapshot, TestFilters, diff --git a/Lib/tracemalloc.py b/Lib/tracemalloc.py index 69b4170..cec99c5 100644 --- a/Lib/tracemalloc.py +++ b/Lib/tracemalloc.py @@ -226,7 +226,7 @@ class Traceback(Sequence): return str(self[0]) def __repr__(self): - s = "