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: PyConfig (PEP 587): PyConfig.warnoptions should have the highest priority
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, ncoghlan, vstinner
Priority: normal Keywords: patch

Created on 2019-09-29 22:54 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16478 merged vstinner, 2019-09-29 22:59
PR 16479 merged miss-islington, 2019-09-29 23:40
Messages (4)
msg353513 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-29 22:54
The PEP 587 says that PyConfig.warnoptions has the highest priority for warnings options:
https://www.python.org/dev/peps/pep-0587/#priority-and-rules

But in the current implementation, PyConfig.warnoptions has... the lowest priority :-(

Attached PR not only fix the issue but also add tests to ensure that every ways to set warnings options have the expected priority.

Priority of warnings options, lowest to highest:

- any implicit filters added by _warnings.c/warnings.py
- PyConfig.dev_mode: "default" filter
- PYTHONWARNINGS environment variable
- '-W' command line options
- PyConfig.bytes_warning ('-b', '-bb'): "default::BytesWarning"
  or "error::BytesWarning" filter
- early PySys_AddWarnOption() calls
- PyConfig.warnoptions
msg353514 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-29 23:40
New changeset fb4ae152a9930f0e00cae8b2807f534058cf341a by Victor Stinner in branch 'master':
bpo-38317: Fix PyConfig.warnoptions priority (GH-16478)
https://github.com/python/cpython/commit/fb4ae152a9930f0e00cae8b2807f534058cf341a
msg353516 - (view) Author: miss-islington (miss-islington) Date: 2019-09-29 23:59
New changeset c9ed9e6fc76323ed537fb79d4232bcd27d82c57e by Miss Islington (bot) in branch '3.8':
bpo-38317: Fix PyConfig.warnoptions priority (GH-16478)
https://github.com/python/cpython/commit/c9ed9e6fc76323ed537fb79d4232bcd27d82c57e
msg353518 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-30 00:29
Oh, the documentation in the PEP 587 was also wrong. I updated it:
https://github.com/python/peps/commit/16bc2821eeb09b4692c372a5a359fd28993cd29b

The "warnings options priority" is currently not documented at:
https://docs.python.org/dev/c-api/init_config.html

The latest major change was bpo-20361 when -b command line option changed to get the highest priority (-b > -W).

cc Nick Coghlan
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82498
2019-09-30 00:29:52vstinnersetstatus: open -> closed

nosy: + ncoghlan
messages: + msg353518

resolution: fixed
stage: patch review -> resolved
2019-09-29 23:59:00miss-islingtonsetnosy: + miss-islington
messages: + msg353516
2019-09-29 23:40:38miss-islingtonsetpull_requests: + pull_request16064
2019-09-29 23:40:21vstinnersetmessages: + msg353514
2019-09-29 22:59:04vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request16063
2019-09-29 22:54:37vstinnercreate