Message255758
| Author |
yselivanov |
| Recipients |
georg.brandl, gvanrossum, larry, ncoghlan, oconnor663, pitrou, serhiy.storchaka, vstinner, yselivanov |
| Date |
2015年12月02日.19:41:55 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1449085315.44.0.613326400579.issue25782@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> Should we do the same for __cause__? Is it possible to create __context__ or __cause__ loop without assigning these attributes directly?
Yes, let's mirror the __context__ behaviour for __cause__. New patch attached.
Serhiy, Guido,
The new patch raises a TypeError in __cause__ and __context__ setters when a cycle was introduced, so in pure Python the following won't work:
# will throw TypeError("cycle in exception context chain")
ex.__context__ = ex chain")
# will throw TypeError("cycle in exception cause chain")
ex.__cause__ = ex
However, since PyException_SetContext and PyException_SetCause are public APIs, and their return type is 'void', I can't raise an error when a C code introduces a cycle, in that case, the exc->cause/exc->context will be set to NULL.
Thoughts?
I think that this approach is the only sane one here. We can certainly fix the infinite loop in PyErr_SetObject, but it will only be a matter of time until we discover a similar loop somewhere else. |
|