-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-125893: Add type check for category argument in warnings.simplefilter and warnings.filterwarning #136305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-125893: Add type check for category argument in warnings.simplefilter and warnings.filterwarning #136305
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on the review. Please add a test case to test_warnings
. You can refer to the devguide if you're unsure how to do that.
Misc/ACKS
Outdated
@@ -2149,5 +2149,6 @@ Jelle Zijlstra | |||
Gennadiy Zlobin | |||
Doug Zongker | |||
Peter Åstrand | |||
Hasrat Ali Arzoo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to keep this sorted by last name. You should be closer to the top.
@@ -250,6 +250,11 @@ def _formatwarnmsg(msg): | |||
msg.filename, msg.lineno, msg.line) | |||
return _wm._formatwarnmsg_impl(msg) | |||
|
|||
def _valid_warning_category(category): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a bit expensive. It's likely worth doing something like this:
if not __debug__:
return True
Oh, also, please add a news entry. |
Thanks for your review! @ZeroIntensity I've addressed all the feedback and updated accordingly. |
This PR addresses gh-125893 by adding a type check for the category argument in warnings.simplefilter and warnings.filterwarning,
Previously, warnings.filterwarnings correctly raised an error when the category argument was not a class, but warnings.simplefilter accepted invalid types without raising any error. This inconsistency could lead to confusion and improper warning filtering.
Both warnings.simplefilter and warnings.filterwarning were not raising any warnings while ran with
python -O
but now this is also handled.