This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients jaraco
Date 2018-03-26.16:40:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1522082434.07.0.467229070634.issue33146@psf.upfronthosting.co.za>
In-reply-to
Content
I propose the following expansion of the interface of contextlib.suppress. Currently, when entering the context, suppress returns None. Instead, it could return an object that provides some detail about the exception.

Inspiration for an implementation exists in pytest (https://github.com/pytest-dev/pytest/blob/ff3d13ed0efab6692a07059b1d61c53eec6e0412/_pytest/python_api.py#L627), capturing the commonly-encountered use-cases, where one wishes to capture, suppress, and then act on a subset of exceptions, allowing others to raise normally.

In [py-181](https://github.com/pytest-dev/py/pull/181), I suggest exposing this functionality generally, but others had an instinct similar to mine - that perhaps the stdlib should be providing this interface.

In addition to saving the exception for inspection, the pytest implementation also allows a "message" to be supplied (for those exceptions where only some subset of the class of Exception is suppressed).

I present this concept here for consideration and feedback. Can contextlib.suppress be expanded with such an interface?
History
Date User Action Args
2018-03-26 16:40:34jaracosetrecipients: + jaraco
2018-03-26 16:40:34jaracosetmessageid: <1522082434.07.0.467229070634.issue33146@psf.upfronthosting.co.za>
2018-03-26 16:40:34jaracolinkissue33146 messages
2018-03-26 16:40:33jaracocreate