Skip to content

bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction#3496

Merged
serhiy-storchaka merged 2 commits into
python:masterfrom
orenmn:bpo31416-fix-assert-failures
Sep 11, 2017
Merged

bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction#3496
serhiy-storchaka merged 2 commits into
python:masterfrom
orenmn:bpo31416-fix-assert-failures

Conversation

@orenmn

@orenmn orenmn commented Sep 11, 2017

Copy link
Copy Markdown
Contributor
  • in _warnings.c: add checks whether the action retrieved from warnings.filters is not a string, and whether warnings.defaultaction is not a string. while we are here, remove a wrong error message.
  • in test_warnings/__init__.py: add a test to verify that the assertion failures are no more.

https://bugs.python.org/issue31416

Comment thread Python/_warnings.c Outdated

if (!PyUnicode_Check(default_action)) {
PyErr_SetString(PyExc_TypeError,
"warnings.defaultaction must be a string");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use MODULE_NAME, as in other error messages. Include an actual type name in error message.

Comment thread Python/_warnings.c Outdated

if (!PyUnicode_Check(action)) {
PyErr_SetString(PyExc_TypeError,
"action must be a string");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Include an actual type name in error message.

@serhiy-storchaka serhiy-storchaka added needs backport to 2.7 type-bug An unexpected behavior, bug, or error labels Sep 11, 2017
@serhiy-storchaka serhiy-storchaka merged commit 9d984fd into python:master Sep 11, 2017
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Sep 12, 2017
…ters or warnings.defaultaction. (pythonGH-3496)

Patch by Oren Milman..
(cherry picked from commit 9d984fd)
@bedevere-bot

Copy link
Copy Markdown

GH-3509 is a backport of this pull request to the 3.6 branch.

serhiy-storchaka added a commit that referenced this pull request Sep 12, 2017
…ters or warnings.defaultaction. (GH-3496) (#3509)

Patch by Oren Milman..
(cherry picked from commit 9d984fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants