[New-bugs-announce] [issue23902] let exception react to being raised or the setting of magic properties (like __cause__) within Python

Travis Everett report at bugs.python.org
Thu Apr 9 22:18:28 CEST 2015


New submission from Travis Everett:

I've been working on a testing tool which raises its own exceptions from those thrown by code under test. The tool's exceptions do some analysis to categorize and add additional information to the underlying exceptions, and they need access to the __cause__ property in order to build this information.

Unfortunately, because the __cause__ property isn't available on the exception objects at init time, some number of workarounds must be employed which make the exception harder to use properly and code handling it less intuitive. While the workarounds are fine at the moment, it would be ideal if the exceptions could be notified instead of burdening the site of each use with workarounds.

It seems sufficient to call a magic method on the exception immediately after these the traceback/cause/context parameters have been set while it is being raised, allowing the exception to perform any essential work. A bells-and-whistles implementation might be a magic method called at raise time with all of these properties as arguments (and the responsibility to deal with them)--but I assume there are reasons exception objects don't already have this level of control.

----------
messages: 240377
nosy: abathur
priority: normal
severity: normal
status: open
title: let exception react to being raised or the setting of magic properties (like __cause__) within Python
type: enhancement
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

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


More information about the New-bugs-announce mailing list