Re: [Python-Dev] peps: New PEP 490: Chain exceptions at C level
On 26.03.15 10:08, victor.stinner wrote:
https://hg.python.org/peps/rev/7daf3bfd9586 changeset: 5741:7daf3bfd9586 user: Victor Stinner <victor.stinner@gmail.com> date: Thu Mar 26 09:08:08 2015 +0100 summary: New PEP 490: Chain exceptions at C level
+Python 3.5 introduces a new private ``_PyErr_ChainExceptions()`` function which +is enough to chain manually exceptions.
It also was added in Python 3.4.3. I meditar about adding _PyErr_ReplaceException() in 2.7 for simpler backporting patches from 3.x.
+Functions like ``PyErr_SetString()`` don't chain automatically exceptions. To +make usage of ``_PyErr_ChainExceptions()`` easier, new functions are added: + +* PyErr_SetStringChain(exc_type, message) +* PyErr_FormatChaine(exc_type, format, ...)
Typo.
+* PyErr_SetNoneChain(exc_type) +* PyErr_SetObjectChain(exc_type, exc_value)
I would first make these functions private, as _PyErr_ChainExceptions(). After proofing their usefulness in the stdlib, they can be made public.
There is another issue: exception chain is not set up on exception creation in python code, only on throwing. Thus I have to assign `__context__` and `__cause__` attributes manually if I want to call `future.set_exception(exc)` instead of `raise exc`. See aiohttp code for usage example: https://github.com/KeepSafe/aiohttp/blob/931efbd518d0d99522d1cd36b43620657cd... On Thu, Mar 26, 2015 at 11:11 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
On 26.03.15 10:08, victor.stinner wrote:
https://hg.python.org/peps/rev/7daf3bfd9586 changeset: 5741:7daf3bfd9586 user: Victor Stinner <victor.stinner@gmail.com> date: Thu Mar 26 09:08:08 2015 +0100 summary: New PEP 490: Chain exceptions at C level
+Python 3.5 introduces a new private ``_PyErr_ChainExceptions()`` function which +is enough to chain manually exceptions.
It also was added in Python 3.4.3.
I meditar about adding _PyErr_ReplaceException() in 2.7 for simpler backporting patches from 3.x.
+Functions like ``PyErr_SetString()`` don't chain automatically exceptions. To +make usage of ``_PyErr_ChainExceptions()`` easier, new functions are added: + +* PyErr_SetStringChain(exc_type, message) +* PyErr_FormatChaine(exc_type, format, ...)
Typo.
+* PyErr_SetNoneChain(exc_type) +* PyErr_SetObjectChain(exc_type, exc_value)
I would first make these functions private, as _PyErr_ChainExceptions(). After proofing their usefulness in the stdlib, they can be made public.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.co...
-- Thanks, Andrew Svetlov
2015-03-26 11:52 GMT+01:00 Andrew Svetlov <andrew.svetlov@gmail.com>:
There is another issue: exception chain is not set up on exception creation in python code, only on throwing.
I'm not suprised of that.
Thus I have to assign `__context__` and `__cause__` attributes manually if I want to call `future.set_exception(exc)` instead of `raise exc`.
Do you mean that we need an helper to make this task even simpler? Or do you suggest to set them automatically in the constructor? Victor
I think setting context in exception constructor would be fine. On Thu, Mar 26, 2015 at 1:36 PM, Victor Stinner <victor.stinner@gmail.com> wrote:
2015-03-26 11:52 GMT+01:00 Andrew Svetlov <andrew.svetlov@gmail.com>:
There is another issue: exception chain is not set up on exception creation in python code, only on throwing.
I'm not suprised of that.
Thus I have to assign `__context__` and `__cause__` attributes manually if I want to call `future.set_exception(exc)` instead of `raise exc`.
Do you mean that we need an helper to make this task even simpler? Or do you suggest to set them automatically in the constructor?
Victor
-- Thanks, Andrew Svetlov
Thanks Serhiy for your review, I modified the PEP. I just sent a first draft (including your suggestions) to python-dev. Victor
participants (3)
-
Andrew Svetlov
-
Serhiy Storchaka
-
Victor Stinner