classification
Title: -W command line options and PYTHONWARNINGS environmental variable should not override -b / -bb command line options
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: 20363 Superseder:
Assigned To: Nosy List: Arfrever, barry, brett.cannon, brian.curtin, eric.araujo, ezio.melotti, jdufresne, jwilk, larry, ncoghlan, pitrou, pjenvey, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2014-01-23 09:19 by Arfrever, last changed 2017-12-12 22:01 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
python-bytes_warnings.patch Arfrever, 2014-01-23 09:19
Pull Requests
URL Status Linked Edit
PR 4734 closed ncoghlan, 2017-12-07 07:24
PR 4820 merged vstinner, 2017-12-12 21:40
Messages (7)
msg208894 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2014-01-23 09:19
Currently -W command line options and PYTHONWARNINGS environmental variable non-intuitively override settings specified by -b / -bb command line options.

$ python3.4 -c 'print("" == b"")'
False
$ python3.4 -b -c 'print("" == b"")'
-c:1: BytesWarning: Comparison between bytes and string
False
$ python3.4 -bb -c 'print("" == b"")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: Comparison between bytes and string
$ python3.4 -We -b -c 'print("" == b"")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
BytesWarning: Comparison between bytes and string
$ python3.4 -Wd -bb -c 'print("" == b"")'
-c:1: BytesWarning: Comparison between bytes and string
False
$ python3.4 -Wi -b -c 'print("" == b"")'
False
$ python3.4 -Wi -bb -c 'print("" == b"")'
False
$


I suggest to increase priority of -b / -bb command line options.
The attached patch should be applied after patch from issue #20355.

(Test suite of Python triggers some BytesWarnings, so firstly they will have to be fixed.)
msg208898 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2014-01-23 09:34
By the way, Tools/scripts/run_tests.py (used by 'test' target in Makefile) passes '-W default -bb', which currently fails work as intended (i.e. treating BytesWarnings as errors).
msg212095 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-24 13:33
Final patch should remove a workaround in Tools/scripts/run_tests.py.
msg217439 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-04-28 22:59
The patch is a bit problematic, because Py_BytesWarningFlag may also be set by e.g. an application embedding Python, but then Python's main.c won't be executed.
msg307792 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-12-07 07:37
The approach I've taken in my PR is similar to the one that Arfrever proposed (albeit different in the details due to other changes in the startup code since that patch was written).

For the embedding case, I've simply noted in the What's New section of the porting guide that embedding applications need to configure a `error::BytesWarning` filter explicitly if they want to treat BytesWarning as errors (in addition to setting the flag to request that the warnings be emitted in the first place).
msg308157 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-12-12 21:59
New changeset 747f48e2e92390c44c72f52a1239959601cde157 by Victor Stinner in branch 'master':
bpo-32230: Set sys.warnoptions with -X dev (#4820)
https://github.com/python/cpython/commit/747f48e2e92390c44c72f52a1239959601cde157
msg308158 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-12-12 22:01
Ok, I merged Nick's PR: -b and -bb options now have the highest priority. I close the issue.
History
Date User Action Args
2017-12-12 22:01:13vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg308158

stage: patch review -> resolved
2017-12-12 21:59:50vstinnersetmessages: + msg308157
2017-12-12 21:40:02vstinnersetpull_requests: + pull_request4711
2017-12-07 07:37:39ncoghlansetmessages: + msg307792
2017-12-07 07:24:18ncoghlansetstage: needs patch -> patch review
pull_requests: + pull_request4647
2017-12-06 11:58:33vstinnersetnosy: + ncoghlan, vstinner
2017-12-06 11:47:47serhiy.storchakalinkissue32231 superseder
2016-10-19 21:57:18jdufresnesetnosy: + jdufresne
2014-06-01 15:28:24serhiy.storchakasetstage: patch review -> needs patch
2014-04-28 22:59:58pitrousetmessages: + msg217439
2014-04-03 20:14:00skrahsetnosy: - skrah
2014-02-24 13:33:13serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg212095
2014-02-15 15:42:07ezio.melottisetnosy: + ezio.melotti
2014-02-10 23:54:58jwilksetnosy: + jwilk
2014-02-06 21:14:26Arfreversetversions: + Python 3.5, - Python 3.4
2014-01-23 09:48:19Arfreversetdependencies: + BytesWarnings triggerred by test suite
2014-01-23 09:34:42Arfreversetmessages: + msg208898
2014-01-23 09:20:26Arfreversetstage: patch review
2014-01-23 09:19:49Arfrevercreate