Yury Selivanov added the comment:
> 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.
----------
Added file: http://bugs.python.org/file41214/Issue25782_2.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25782>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com