[New-bugs-announce] [issue28410] Add convenient C API for "raise ... from ..."

Serhiy Storchaka report at bugs.python.org
Mon Oct 10 15:50:27 EDT 2016


New submission from Serhiy Storchaka:

Sometimes after catching an exception we need to raise new exception of specific type, but save the information about current exception. In Python the syntax "raise ... from ..." serves this purpose (PEP 3134). But in C the code that implements this is too cumbersome. Proposed patch adds private convenient function that raises an exception and sets previously raised exception as its __context__ and __cause__ attributes. This is a generalized version of gen_chain_runtime_error() from Objects/genobject.c. It could be reused in three other places: Objects/abstract.c, Objects/unicodeobject.c, and Modules/zipimport.c (currently only __context__ is set, but setting __cause__ looks preferable), and in new code for issue28214. Maybe there are other opportunities.

----------
components: Interpreter Core
files: _PyErr_FormatFromCause.patch
keywords: patch
messages: 278441
nosy: haypo, serhiy.storchaka, yselivanov
priority: normal
severity: normal
stage: patch review
status: open
title: Add convenient C API for "raise ... from ..."
type: enhancement
versions: Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45050/_PyErr_FormatFromCause.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28410>
_______________________________________


More information about the New-bugs-announce mailing list