TST: require expected_warning and match in assert_produces_warning - #67513
Merged
mroeschke merged 1 commit intoAug 31, 2026
Merged
Conversation
Follow-up to GH#67275. Enforce the message assertion in the signature of assert_produces_warning itself rather than with a pre-commit check: expected_warning becomes a required positional and match must be passed whenever a warning is expected, with match=None as the opt-out. Drops the Warning default for expected_warning, so a call can no longer accept any warning class by accident, and removes the now-redundant bare_assert_produces_warning check along with its hook and tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mroeschke
reviewed
Aug 30, 2026
jbrockmendel
marked this pull request as ready for review
August 31, 2026 14:42
mroeschke
approved these changes
Aug 31, 2026
Member
|
Thanks @jbrockmendel |
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.
Follow-up to GH-67275, taking up @mroeschke's suggestion there: instead of a pre-commit check, enforce the message assertion in the signature of
assert_produces_warningitself.expected_warningbecomes a required positional. Dropping itsWarningdefault removes a footgun the lint check did not address at all:assert_produces_warning(match="...")previously accepted any warning class.matchdefaults tolib.no_default; passing a truthyexpected_warningwithout it raisesTypeError.match=Noneremains the opt-out, the same spelling the lint check accepted.maybe_produces_warningtakesmatchas a required keyword-only argument, so thecondition=Falsebranch is covered too.Making
matchunconditionally required was the other option, but it would mean adding a meaninglessmatch=Noneto the 221assert_produces_warning(None)/(False)calls, which assert that nothing is warned and so have no message to match. The sentinel keeps those untouched.This supersedes the
bare_assert_produces_warningcheck, which is removed here along with its pre-commit hook and script tests. The signature covers every call site in the repo rather than justpandas/tests/, sees through variables (the static check needed a hand-written exemption for a parametrizedfalse_or_none), and needs no maintained script. The one thing it gives up is a bare call in a test that never runs in any CI job.An AST sweep of the whole repo found 48 calls relying on the old
Warningdefault, all inpandas/tests/interchange/; those now namePandas4Warningexplicitly. No call anywhere passed a truthyexpected_warningwithoutmatch— GH-67275 had already fixed those — so there is no other call-site churn.Full
pandas/testsrun is green (244207 passed, 8486 skipped, 1510 xfailed) andpre-commit run --all-filespasses with no files modified.AI disclosure: drafted with Claude Code (
claude opus 5 (high)), which prototyped the signature change, ran the AST sweep over call sites, and ran the test suite and pre-commit.