This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: assertion failures in warn_explicit() in case of a bad warnings.filters or warnings.defaultaction
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-09-11 07:52 by Oren Milman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3496 merged Oren Milman, 2017-09-11 10:49
PR 3509 merged serhiy.storchaka, 2017-09-12 06:32
Messages (3)
msg301867 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-11 07:52
The following code causes an assertion failure in warn_explicit() (in
Python/_warnings.c):

import warnings
warnings.filters = [(None, None, Warning, None, 0)]
warnings.warn_explicit(message='foo', category=Warning, filename='bar',
                       lineno=1)

this is because warn_explicit() assumes that get_filter() returned a string,
and passes the return value (of get_filter()) to _PyUnicode_EqualToASCIIString(),
which asserts it received a string.


In addition, get_filter() might return warnings.defaultaction, and so the
following code also causes an assertion failure in warn_explicit():

import warnings
warnings.defaultaction = None
warnings.filters = []
warnings.warn_explicit(message='foo', category=Warning, filename='bar',
                       lineno=1)
msg301903 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-11 21:18
New changeset 9d984fd2b097c8c29479d1c3eb740995fe1ccb0d by Serhiy Storchaka (Oren Milman) in branch 'master':
bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction. (#3496)
https://github.com/python/cpython/commit/9d984fd2b097c8c29479d1c3eb740995fe1ccb0d
msg301940 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-12 06:48
New changeset 9adc87b0f82e5169c5f44739f89212a86013d1c4 by Serhiy Storchaka in branch '3.6':
[3.6] bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction. (GH-3496) (#3509)
https://github.com/python/cpython/commit/9adc87b0f82e5169c5f44739f89212a86013d1c4
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75597
2017-09-12 06:48:53serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-09-12 06:48:30serhiy.storchakasetmessages: + msg301940
2017-09-12 06:32:41serhiy.storchakasetpull_requests: + pull_request3504
2017-09-11 21:18:11serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg301903
2017-09-11 10:49:09Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3489
2017-09-11 07:52:58Oren Milmancreate