Author mb_
Recipients mb_, ncoghlan, yselivanov
Date 2016-08-20.12:28:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471696082.59.0.515606435532.issue27814@psf.upfronthosting.co.za>
In-reply-to
Content
This adds a whitelist parameter with the name 'unless' to contextlib.suppress, so one can specify exceptions that will not be suppressed.

This is useful for specifying single sub-exceptions that we still want to catch, even of we want to suppress all other siblings.

Or it can be used to suppress all exceptions except some very specific ones by suppressing BaseException and whitelisting things like SyntaxError, NameError and the like.

Usage looks like this:

with suppress(OSError, unless = PermissionError):
    with open("foobar", "wb") as f:
        f.write(...


I selected the name 'unless' instead of 'whitelist' or such, because I think that pronounces nicely in the 'with' line context. However please feel free to make better suggestions.
History
Date User Action Args
2016-08-20 12:28:02mb_setrecipients: + mb_, ncoghlan, yselivanov
2016-08-20 12:28:02mb_setmessageid: <1471696082.59.0.515606435532.issue27814@psf.upfronthosting.co.za>
2016-08-20 12:28:02mb_linkissue27814 messages
2016-08-20 12:28:02mb_create