Skip to content

gh-153128: Preserve once warnings across filter changes#153697

Draft
snoopuppy582 wants to merge 1 commit into
python:mainfrom
snoopuppy582:fix/warnings-once-filter-change
Draft

gh-153128: Preserve once warnings across filter changes#153697
snoopuppy582 wants to merge 1 commit into
python:mainfrom
snoopuppy582:fix/warnings-once-filter-change

Conversation

@snoopuppy582

@snoopuppy582 snoopuppy582 commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • keep the C implementation's "once" warning tracking in the global once registry
  • make that registry independent of warning filter version changes, matching _py_warnings
  • add a shared regression test for the C and pure Python implementations
  • add a Library NEWS entry

The C implementation previously reused the per-module warning registry whenever one was available. That registry is deliberately cleared when the filter version changes, so adding even an unrelated filter caused a warning governed by "once" to be emitted again. The pure Python implementation stores the (text, category) key in onceregistry, which is not filter-versioned.

This change factors the key lookup/update logic from the versioned registry helper and uses it with the global once registry. "default" and "module" tracking remain versioned as before.

Fixes #153128.

Tests

  • PCbuild/build.bat -p x64 -c Debug
  • PCbuild/amd64/python_d.exe -m unittest -v test.test_warnings.CFilterTests.test_once_after_filter_change test.test_warnings.PyFilterTests.test_once_after_filter_change
  • PCbuild/amd64/python_d.exe -m test -v test_warnings
  • PCbuild/amd64/python_d.exe -X context_aware_warnings=1 -m test test_warnings
  • PCbuild/amd64/python_d.exe -m test -R 3:3 test_warnings
  • PCbuild/amd64/python_d.exe Tools/patchcheck/patchcheck.py

AI assistance

OpenAI Codex was used to assist with duplicate research, reproduction, root-cause analysis, the C implementation and regression test, and local verification. The code and this PR description were prepared with that assistance; this PR is submitted as a draft for review.

Keep the C implementation's once registry independent of filter version changes, matching the pure Python implementation. Add a shared regression test and a Library news entry.
@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warnings: adding new filter resets prior existing "once" filters

1 participant