[issue27814] contextlib.suppress: Add whitelist argument

2016-08-23 Thread Nick Coghlan
Nick Coghlan added the comment: Thanks for being understanding of the decision. Regarding my comment above about __subclasscheck__ potentially letting you implement this without changing the signature of suppress, here's an example of how you might be able to do that. First, define a metaclas

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-22 Thread Michael Büsch
Michael Büsch added the comment: >an implementation of the vastly *less* common pattern: Ok, here are some numbers. My codebase is about 32 kLOC. $ git grep suppressAllExc |wc -l 20 $ git grep contextlib\\.suppress |wc -l 17 (suppressAllExc being my local version to suppress Exception, but exc

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Nick Coghlan
Nick Coghlan added the comment: contextlib.suppress provides a contextmanager spelling for the following pattern: try: except : pass That's a very common pattern worth having in the standard library, even though it's only a 5 line context manager. The proposed API ch

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
Michael Büsch added the comment: >when particular instances of "catch this exception, but not these ones" become >common, we tend to *change the standard exception hierarchy* to eliminate them >(e.g. StopIteration, KeyboardError, GeneratorExit no longer inheriting from >Exception). But my pat

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Nick Coghlan
Nick Coghlan added the comment: It's the "really common problem" assertion that I'm disputing - when particular instances of "catch this exception, but not these ones" become common, we tend to *change the standard exception hierarchy* to eliminate them (e.g. StopIteration, KeyboardError, Gene

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
Michael Büsch added the comment: >and instead point you towards https://bugs.python.org/issue12029 Fair enough. But how would a 'suppress OSError, but catch FileNotFoundError' look like with this for example? (Note that I can't subclass the exception) >I'm also not sure it's an idiom we reall

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Nick Coghlan
Nick Coghlan added the comment: Michael, first of all, thanks for taking the time to propose this idea, and put together a patch for it. Unfortunately, I'm going to have to decline the proposal for API design reasons (which I'll explain below), and instead point you towards https://bugs.pytho

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
Michael Büsch added the comment: Thanks for your comments. Here's version 2 of the patch. Changes: - A typo in the docstring was fixed. - Space was removed in keyword assignments. - Documentation was added. (Note that I signed and sent the contributor agreement. It should arrive soon.) ---

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread SilentGhost
SilentGhost added the comment: Spaces around '=' sign in function definitions/calls. -- ___ Python tracker ___ ___ Python-bugs-list ma

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
Michael Büsch added the comment: >Could you please produce a patch that conforms to PEP-8. I tried hard to do so. Could you please tell me what parts are not compliant, so I can fix them? -- ___ Python tracker __

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread SilentGhost
SilentGhost added the comment: Also, these would need documentation changes. -- ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread SilentGhost
SilentGhost added the comment: Could you please produce a patch that conforms to PEP-8. -- nosy: +SilentGhost stage: -> patch review versions: +Python 3.6 ___ Python tracker ___

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Barry A. Warsaw
Changes by Barry A. Warsaw : -- nosy: +barry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
Changes by Michael Büsch : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.py

[issue27814] contextlib.suppress: Add whitelist argument

2016-08-20 Thread Michael Büsch
New submission from Michael Büsch: 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 si