From 9797b7ae4496627836c55333765e10201a9840e3 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 10 Sep 2018 20:02:33 +0300 Subject: [PATCH] bpo-26502: Implement FrameSummary.__len__() (GH-8632) --- Lib/test/test_traceback.py | 5 +++++ Lib/traceback.py | 3 +++ .../next/Library/2018-08-02-20-39-32.bpo-26502.eGXr_k.rst | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-08-02-20-39-32.bpo-26502.eGXr_k.rst diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 8a3aa8a8648..3af85b81721 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -868,6 +868,7 @@ class MiscTracebackCases(unittest.TestCase): (__file__, lineno+2, 'test_extract_stack', 'result = extract()'), (__file__, lineno+1, 'extract', 'return traceback.extract_stack()'), ]) + self.assertEqual(len(result[0]), 4) class TestFrame(unittest.TestCase): @@ -900,6 +901,10 @@ class TestFrame(unittest.TestCase): f = traceback.FrameSummary("f", 1, "dummy", line="line") self.assertEqual("line", f.line) + def test_len(self): + f = traceback.FrameSummary("f", 1, "dummy", line="line") + self.assertEqual(len(f), 4) + class TestStack(unittest.TestCase): diff --git a/Lib/traceback.py b/Lib/traceback.py index 4e7605d15fa..ab35da94b51 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -279,6 +279,9 @@ class FrameSummary: return "".format( filename=self.filename, lineno=self.lineno, name=self.name) + def __len__(self): + return 4 + @property def line(self): if self._line is None: diff --git a/Misc/NEWS.d/next/Library/2018-08-02-20-39-32.bpo-26502.eGXr_k.rst b/Misc/NEWS.d/next/Library/2018-08-02-20-39-32.bpo-26502.eGXr_k.rst new file mode 100644 index 00000000000..3a3fc17e22d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-08-02-20-39-32.bpo-26502.eGXr_k.rst @@ -0,0 +1,2 @@ +Implement ``traceback.FrameSummary.__len__()`` method to preserve +compatibility with the old tuple API.