This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Broken compatibility in FrameSummary equality
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: berker.peksag, python-dev, rbcollins, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2015-09-14 17:48 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
traceback_FrameSummary_equality.patch serhiy.storchaka, 2015-09-14 17:49 review
traceback_FrameSummary_equality_2.patch serhiy.storchaka, 2015-09-18 07:23 review
Messages (7)
msg250693 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-14 17:48
Since 3.5 traceback.extract_tb() and traceback.extract_stack() return a list (actually list's subclass StackSummary) of FrameSummary objects instead of a list of tuples. FrameSummary is not fully compatible with tuple. One important incompatibility is in the comparing.

>>> import traceback
>>> traceback.extract_stack()[0] == ('<stdin>', 1, '<module>', '')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-3.5/Lib/", line 254, in __eq__
    return (self.filename == other.filename and
AttributeError: 'tuple' object has no attribute 'filename'

In general __eq__ shouldn't raise an exception. Issue25108 is needed to be fixed first for tests.

Here is a patch that restores compatibility.

An alternative solution would be to make FrameSummary a subclass of tuple (namedtuple).
msg250953 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-18 07:23
Fixed patch and added tests.
msg251722 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-27 20:11
msg251760 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-09-28 11:19

+        self.assertEqual(f, tuple(f))
+        self.assertEqual(tuple(f), f)

It would be good to add a comment to explain why we test both variants, but it's not really important.
msg251834 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-29 09:49
traceback_FrameSummary_equality_2.patch looks good to me, but I have the same remark than Berker (see the review).
msg251835 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-09-29 09:51
LGTM too.
msg251880 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-29 19:36
New changeset 2ecb7d4d9e0b by Serhiy Storchaka in branch '3.5':
Issue #25111: Fixed comparison of traceback.FrameSummary.

New changeset f043182a81d7 by Serhiy Storchaka in branch 'default':
Issue #25111: Fixed comparison of traceback.FrameSummary.
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69298
2015-09-29 19:37:09serhiy.storchakasetstatus: open -> closed
assignee: serhiy.storchaka
resolution: fixed
stage: commit review -> resolved
2015-09-29 19:36:33python-devsetnosy: + python-dev
messages: + msg251880
2015-09-29 09:51:29rbcollinssetmessages: + msg251835
2015-09-29 09:49:21vstinnersetnosy: + vstinner
messages: + msg251834
2015-09-28 11:19:13berker.peksagsetnosy: + berker.peksag

messages: + msg251760
stage: patch review -> commit review
2015-09-27 20:11:09serhiy.storchakasetmessages: + msg251722
2015-09-18 07:23:20serhiy.storchakasetfiles: + traceback_FrameSummary_equality_2.patch

messages: + msg250953
2015-09-14 17:49:00serhiy.storchakasetfiles: + traceback_FrameSummary_equality.patch
keywords: + patch
2015-09-14 17:48:43serhiy.storchakacreate