Chris Jerdonek <chris.jerdo...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue25782>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to