Skip to content

Conversation

DanielNoord
Copy link
Contributor

@DanielNoord DanielNoord commented Mar 18, 2022

This is a submit of the patch provided by @ berkerpeksag in bpo-16845. I added one additional test case.
Not sure if I should ping them here.

It supersedes #26696 which did not received any interaction after the initial push and has now been marked stale.

https://bugs.python.org/issue16845

Closes #61049

Co-authored-by: Berker Peksag <berker.peksag@gmail.com>
@@ -274,7 +274,11 @@ def __enter__(self):
v.__warningregistry__ = {}
self.warnings_manager = warnings.catch_warnings(record=True)
self.warnings = self.warnings_manager.__enter__()
warnings.simplefilter("always", self.expected)
if isinstance(self.expected, tuple):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably be done in a separate PR, but issubclass does not support a tuple. However, the type of the category parameter of warnings.simplefilter doesn't really indicate that it should support a tuple anyway.
I could also change it so that the issubclass checks for tuples before doing the check, but I'm not sure if that is actually correct.

Let me know!

Copy link
Member

Choose a reason for hiding this comment

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

I think that there may be a third-party code which uses simplefilter() with a tuple. Instead of changing unittest, it is better to make the argument check in simplefilter() more lenient.

It would be nice to make also filterwarnings() accepting a tuple.

@DanielNoord DanielNoord reopened this Mar 23, 2022
Copy link
Contributor

@MaxwellDupre MaxwellDupre left a comment

Choose a reason for hiding this comment

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

Ran 117 tests in 2.152s
OK
Looks ok to me.

@DanielNoord
Copy link
Contributor Author

@berkerpeksag Gentle ping as this is basically your patch from https://bugs.python.org/issue16845 > https://bugs.python.org/file35773/issue16845.diff.

Sorry if such pings are not appreciated!

@DanielNoord
Copy link
Contributor Author

I'm closing this PR. On master warnings.simplefilter("error", int) works fine so I don't see a reason to add stricter validation here.

@serhiy-storchaka if you agree do you mind closing the associated issue?

@DanielNoord DanielNoord closed this Jun 4, 2024
@DanielNoord DanielNoord deleted the fix-issue-16845 branch June 4, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warnings.simplefilter should validate input
6 participants