Skip to content

gh-125854: Improve error messages for invalid category in the warnings module #137750

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 14, 2025

  • Include the type name if category is a type, but not a Warning subtype, instead of just 'type'.
  • Validate category in simplefilter().

…ngs.warn()

Include the type name if category is a type, but not a Warning
subtype, instead of just 'type'.
@serhiy-storchaka serhiy-storchaka force-pushed the warnings-invalid-category branch from a25815d to ad15208 Compare August 14, 2025 08:27
@serhiy-storchaka
Copy link
Member Author

I initially added more details in the error message filterwarning() and added the same check in simplefilter(), but then removed them. simplefilter() supports not only subclasses of Warning (although this is not documented), and there are plans to allow this in filterwarning().

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@serhiy-storchaka serhiy-storchaka merged commit c47ffbf into python:main Aug 14, 2025
48 checks passed
@serhiy-storchaka serhiy-storchaka deleted the warnings-invalid-category branch August 14, 2025 11:59
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.

2 participants