gh-125893: Add type check for category argument in warnings.simplefilter and warnings.filterwarning - #136305
gh-125893: Add type check for category argument in warnings.simplefilter and warnings.filterwarning#136305hasrat17 wants to merge 10 commits into
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 |
ZeroIntensity
left a comment
There was a problem hiding this comment.
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.
| Gennadiy Zlobin | ||
| Doug Zongker | ||
| Peter Åstrand | ||
| Hasrat Ali Arzoo |
There was a problem hiding this comment.
We try to keep this sorted by last name. You should be closer to the top.
|
Oh, also, please add a news entry. |
|
Thanks for your review! @ZeroIntensity I've addressed all the feedback and updated accordingly. |
|
Hi @ZeroIntensity |
| if isinstance(category, type) and issubclass(category, Warning): | ||
| return True | ||
| if isinstance(category, tuple): | ||
| if __debug__: |
There was a problem hiding this comment.
I'd still consider the isinstance checks above to be expensive. Could you move this __debug__ check to before any calls to isinstance?
There was a problem hiding this comment.
Moved __debug__ before any other checks
| with self.assertRaises(ValueError): | ||
| self.module.simplefilter('ignore', lineno=-1) | ||
|
|
||
| def test_invalid_category_types(self): |
There was a problem hiding this comment.
We probably need to skip this if we're not in debug mode, so add something like @unittest.skipUnless(__debug__, ...).
…D8Nyd.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Fixed the linting error
|
Hi @ZeroIntensity |
|
This PR is stale because it has been open for 30 days with no activity. |
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 -Obut now this is also handled.