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 <rep...@bugs.python.org>
<http://bugs.python.org/issue28410>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to