[Python-checkins] cpython (3.5): Issue #25111: Fixed comparison of traceback.FrameSummary.
serhiy.storchaka
python-checkins at python.org
Tue Sep 29 21:36:30 CEST 2015
https://hg.python.org/cpython/rev/2ecb7d4d9e0b
changeset: 98405:2ecb7d4d9e0b
branch: 3.5
parent: 98403:da9ad20dd470
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Sep 29 22:33:36 2015 +0300
summary:
Issue #25111: Fixed comparison of traceback.FrameSummary.
files:
Lib/test/test_traceback.py | 16 +++++++++++-----
Lib/traceback.py | 12 ++++++++----
Misc/NEWS | 2 ++
3 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -640,7 +640,7 @@
return traceback.extract_stack()
result = extract()
lineno = extract.__code__.co_firstlineno
- self.assertEqual([tuple(x) for x in result[-2:]], [
+ self.assertEqual(result[-2:], [
(__file__, lineno+2, 'test_extract_stack', 'result = extract()'),
(__file__, lineno+1, 'extract', 'return traceback.extract_stack()'),
])
@@ -652,10 +652,16 @@
linecache.clearcache()
linecache.lazycache("f", globals())
f = traceback.FrameSummary("f", 1, "dummy")
- self.assertEqual(
- ("f", 1, "dummy", '"""Test cases for traceback module"""'),
- tuple(f))
- self.assertEqual(None, f.locals)
+ self.assertEqual(f,
+ ("f", 1, "dummy", '"""Test cases for traceback module"""'))
+ self.assertEqual(tuple(f),
+ ("f", 1, "dummy", '"""Test cases for traceback module"""'))
+ self.assertEqual(f, traceback.FrameSummary("f", 1, "dummy"))
+ self.assertEqual(f, tuple(f))
+ # Since tuple.__eq__ doesn't support FrameSummary, the equality
+ # operator fallbacks to FrameSummary.__eq__.
+ self.assertEqual(tuple(f), f)
+ self.assertIsNone(f.locals)
def test_lazy_lines(self):
linecache.clearcache()
diff --git a/Lib/traceback.py b/Lib/traceback.py
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -257,10 +257,14 @@
dict((k, repr(v)) for k, v in locals.items()) if locals else None
def __eq__(self, other):
- return (self.filename == other.filename and
- self.lineno == other.lineno and
- self.name == other.name and
- self.locals == other.locals)
+ if isinstance(other, FrameSummary):
+ return (self.filename == other.filename and
+ self.lineno == other.lineno and
+ self.name == other.name and
+ self.locals == other.locals)
+ if isinstance(other, tuple):
+ return (self.filename, self.lineno, self.name, self.line) == other
+ return NotImplemented
def __getitem__(self, pos):
return (self.filename, self.lineno, self.name, self.line)[pos]
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,8 @@
Library
-------
+- Issue #25111: Fixed comparison of traceback.FrameSummary.
+
- Issue #25262. Added support for BINBYTES8 opcode in Python implementation of
unpickler. Highest 32 bits of 64-bit size for BINUNICODE8 and BINBYTES8
opcodes no longer silently ignored on 32-bit platforms in C implementation.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list