Skip to content
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

gh-128384: Use contextvar for catch_warnings() #128463

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nascheme
Copy link
Member

@nascheme nascheme commented Jan 3, 2025

This changes warnings.catch_warnings() to use a contextvar for the new list of filters. If catch_warnings is not used, the list of filters is the module global warnings.filters. When the context manager is active, the effective list of filters is warnings.get_context()._filters.

This change is on top of two other unmerged PRs:


📚 Documentation preview 📚: https://cpython-previews--128463.org.readthedocs.build/

By default, inherit the context from the thread calling
`Thread.start()`.
Expose the mutex from _warnings.c and hold it when mutating the filters
list or the filters version.
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.

1 participant