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

bpo-39912: Raise appropriate exceptions in filterwarnings() and simplefilter() #18878

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

remilapeyre
Copy link
Contributor

@remilapeyre remilapeyre commented Mar 9, 2020

Lib/warnings.py Outdated Show resolved Hide resolved
Lib/warnings.py Outdated Show resolved Hide resolved
"once"), "invalid action: %r" % (action,)
assert isinstance(lineno, int) and lineno >= 0, \
"lineno must be an int >= 0"
if action not in ("error", "ignore", "always", "default", "module", "once"):
Copy link
Member

@serhiy-storchaka serhiy-storchaka Mar 12, 2020

Choose a reason for hiding this comment

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

What about the category argument?

Also it may be worth to move the duplicated code into a subfunction.

Copy link
Contributor Author

@remilapeyre remilapeyre Apr 8, 2020

Choose a reason for hiding this comment

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

The category argument is a bit different, it's supposed to be a subclass of Warning and nothing else but in some cases like https://github.com/python/cpython/blob/master/Lib/unittest/test/test_case.py#L1435 it will get called with a tuple.

Should we relax the condition on category so it accepts tuples of Warning subclasses too or fix unittest so it calls simplefilter() multiple time when given a iterable?

Rémi Lapeyre and others added 2 commits Apr 8, 2020
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
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.

None yet

5 participants