From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 16 Dec 2020 22:01:14 +0000 (-0800) Subject: bpo-37961: Fix regression in tracemalloc.Traceback.__repr__ (GH-23805) X-Git-Tag: v3.9.2rc1~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78062e07bc7c3b47ffdcdec786b259dda376370c;p=thirdparty%2FPython%2Fcpython.git bpo-37961: Fix regression in tracemalloc.Traceback.__repr__ (GH-23805) Regression in 8d59eb1b66c51b2b918da9881c57d07d08df43b7. (cherry picked from commit 051b9818671625d125dee8198e0d2af5ad4c85b8) Co-authored-by: Daniel Hahler --- diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py index c5ae4e6d653b..b10d1798c297 100644 --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -84,6 +84,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(): @@ -1064,6 +1083,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 69b4170ec824..cec99c59700f 100644 --- a/Lib/tracemalloc.py +++ b/Lib/tracemalloc.py @@ -226,7 +226,7 @@ class Traceback(Sequence): return str(self[0]) def __repr__(self): - s = "