Author chris.jerdonek
Recipients Dennis Sweeney, Rotem Yaari, Yury.Selivanov, chris.jerdonek, georg.brandl, larry, larsonreever, ncoghlan, oconnor663, python-dev, serhiy.storchaka, terry.reedy, vstinner, yselivanov
Date 2020-05-31.09:28:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1590917325.07.0.844611729939.issue25782@roundup.psfhosted.org>
In-reply-to
Content
I think this issue needs deeper discussion to know how to proceed.

> If there is a chain A -> B -> C -> D -> E, after assignment C.__context__ = A we will get a chain C -> A -> B -> D -> E. No exception is lost.

I understand not wanting to lose exceptions here. However, if there were a separate exception F and the assignment were instead C.__context__ = F without raising C, the new chain would be A -> B -> C -> F. We would again lose D -> E. So why is that not a problem here, and yet it's a problem above? If we really didn't want to lose the exception, we could make it A -> B -> C -> F -> D -> E (and if raising C, it would become C -> F -> D -> E).

Thus, I think we may want to consider separately the cases of explicitly setting the context (calling PyException_SetContext) and implicitly setting it (calling PyErr_SetObject). Maybe when setting explicitly, losing the previous value is okay.

Also, there's another option for the top example in the implicit case of raising C. We could create a copy C' of C, so the new chain would be C -> A -> B -> C' -> D -> E. The code already has logic to create a new exception in certain cases: both _PyErr_SetObject and _PyErr_NormalizeException call _PyErr_CreateException. There are yet more options but I don't want to lengthen this comment further.

Lastly, regarding Dennis's patch, I think the question of how to detect cycles should be discussed separately from what the behavior should be.
History
Date User Action Args
2020-05-31 09:28:45chris.jerdoneksetrecipients: + chris.jerdonek, georg.brandl, terry.reedy, ncoghlan, vstinner, larry, Yury.Selivanov, python-dev, serhiy.storchaka, yselivanov, oconnor663, Rotem Yaari, larsonreever, Dennis Sweeney
2020-05-31 09:28:45chris.jerdoneksetmessageid: <1590917325.07.0.844611729939.issue25782@roundup.psfhosted.org>
2020-05-31 09:28:45chris.jerdoneklinkissue25782 messages
2020-05-31 09:28:43chris.jerdonekcreate