gh-91230: Concise catch_warnings with simplefilter#91435
Merged
JelleZijlstra merged 4 commits intopython:mainfrom Apr 24, 2022
Merged
gh-91230: Concise catch_warnings with simplefilter#91435JelleZijlstra merged 4 commits intopython:mainfrom
JelleZijlstra merged 4 commits intopython:mainfrom
Conversation
AlexWaygood
reviewed
Apr 11, 2022
Misc/NEWS.d/next/Library/2022-04-10-17-12-23.gh-issue-91230.T1d_fG.rst
Outdated
Show resolved
Hide resolved
3bac2a9 to
2098a68
Compare
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
The idea and implementation look solid.
2098a68 to
f7056ea
Compare
Contributor
Author
|
Thanks @JelleZijlstra for your review! I've updated the docs accordingly; let me know if there's anything else 😄 |
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
Noticed one more thing while re-reviewing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #91230, which was in turn motivated by pytest-dev/pytest#9404 (comment) and pytest-dev/pytest#9745 (comment): users evidently want a concise context manager to ignore all warnings in some block of code, and to error on warnings on some block of code.
Of course that can be done with the standard library
with warnings.catch_warnings():pluswarnings.simplefilter(...); but in practice this is quite rare. I believe that the trivial friction of needing two statements plays a substantial role here, and therefore thatwith warnings.catch_warnings(action="error"):(oraction="ignore") would be a substantial win for many people, especially in tests.I've specifically chosen
simplefilteroverfilterwarningsbecause the latter has a conflictingmoduleparameter.