bpo-16845: add category type check to warnings.simplefilter#26696
Closed
Bonifacio2 wants to merge 4 commits into
Closed
bpo-16845: add category type check to warnings.simplefilter#26696Bonifacio2 wants to merge 4 commits into
Bonifacio2 wants to merge 4 commits into
Conversation
Co-authored-by: Vajrasky Kok
| "once"), "invalid action: %r" % (action,) | ||
| assert isinstance(lineno, int) and lineno >= 0, \ | ||
| "lineno must be an int >= 0" | ||
| assert isinstance(category, type), "category must be a class" |
Contributor
There was a problem hiding this comment.
I prefer the implementation from the patch by @berkerpeksag:
if not (isinstance(category, type) and issubclass(category, Warning)):
raise TypeError('category must be a Warning subclass, '
'not {!r}'.format(category))
You can emulate something close.
You can emulate some parts of the test from the same patch:
+ def test_simplefilter_invalid_category(self):
+ class MyWarningClass(Warning):
+ pass
+
+ class NonWarningSubclass:
+ pass
+
+ msg_regex = 'category must be a Warning subclass, not (.*)'
+
+ with self.assertRaisesRegex(TypeError, msg_regex):
+ self.module.simplefilter('always', '')
+
+ with self.assertRaisesRegex(TypeError, msg_regex):
+ self.module.simplefilter('always', NonWarningSubclass)
+
+ with self.assertRaisesRegex(TypeError, msg_regex):
+ self.module.simplefilter('always', MyWarningClass())
Contributor
Author
There was a problem hiding this comment.
Thank you for the suggestion. I'll take a look at this.
I also have to get some context on the failing tests. Not sure why they are failing.
Contributor
Author
There was a problem hiding this comment.
Taking a look at this now. I might update this PR soon.
|
This PR is stale because it has been open for 30 days with no activity. |
Contributor
Author
|
This PR turned obsolete given the following PR: #61049 |
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.
Co-authored-by: Vajrasky Kok
https://bugs.python.org/issue16845