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: -W command line options should have higher priority than PYTHONWARNINGS environmental variable
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: 20373 Superseder:
Assigned To: Nosy List: Arfrever, barry, brett.cannon, brian.curtin, eric.araujo, ezio.melotti, larry, pitrou, pjenvey, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-01-22 21:41 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-warnings.patch Arfrever, 2014-01-24 03:17
Messages (13)
msg208854 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2014-01-22 21:41
Currently Python has non-intuitive behavior such that PYTHONWARNINGS environmental variable has higher priority than -W command line options.

$ python3.4 -c '__import__("warnings").warn("xxx", DeprecationWarning)'
$ python3.4 -Wd -c '__import__("warnings").warn("xxx", DeprecationWarning)'
-c:1: DeprecationWarning: xxx
$ python3.4 -We -c '__import__("warnings").warn("xxx", DeprecationWarning)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
DeprecationWarning: xxx
$ PYTHONWARNINGS="e" python3.4 -Wd -c '__import__("warnings").warn("xxx", DeprecationWarning)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
DeprecationWarning: xxx
$ PYTHONWARNINGS="d" python3.4 -We -c '__import__("warnings").warn("xxx", DeprecationWarning)'
-c:1: DeprecationWarning: xxx
$


I think that settings from -W command line options should have higher priority than PYTHONWARNINGS environmental variable.

(Adding people from issue #7301 to nosy list.)
msg208856 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-22 22:07
Agreed.
msg208886 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2014-01-23 08:59
The attached patch moves calls to PySys_AddWarnOption* for -W options to after parsing PYTHONWARNINGS.

I think that this bug fix could be applied in Python 3.4. The patch does not introduce any failures in full test suite.
msg209018 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-23 23:19
Well, 3.4 isn't supposed to receive behaviour changes anymore, unless Larry says it's ok.
msg209022 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-23 23:30
About the patch (note the code review tool hasn't accepted it, so I'm commenting here):
- in the tests, I think comparing stderr as-is will fail under Windows, where the line separator is b"\r\n"; better call splitlines() first
- in the tests, I think it would be better to use test.script_helper.assert_python_ok() (it will automate some stuff for you), even though other tests don't in that file
- in main.c, you need to Py_DECREF warning_options when you are done with it.
msg209026 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-24 00:02
Is this behavior causing problems?  How bad is it?

Can I get more opinions about this than just Arfrever and Antoine?  Not that I don't trust their opinions, I just want to see a larger sample size.
msg209028 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-24 00:05
> Is this behavior causing problems?  How bad is it?

Not really. It's just a bit suboptimal and counter-intuitive
(local settings should trump global settings).
msg209031 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2014-01-24 03:17
The new patch includes changes suggested by Antoine. (This patch should be applied after patch from issue #20373.)
msg209089 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-01-24 14:51
I agree with Antoine; this can wait for Python 3.5.
msg209090 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-24 15:03
Okay, then yes, let's save this for 3.5.  Thanks!
msg212094 - (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.
msg217437 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-04-28 22:58
New changeset 78c0d80a04f9 by Antoine Pitrou in branch 'default':
Issue #20355: -W command line options now have higher priority than the PYTHONWARNINGS environment variable.  Patch by Arfrever.
http://hg.python.org/cpython/rev/78c0d80a04f9

New changeset 925c0b611c02 by Antoine Pitrou in branch 'default':
Remove a workaround for fixed issue #20355.
http://hg.python.org/cpython/rev/925c0b611c02
msg217438 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-04-28 22:58
Committed. Thanks, Arfrever!
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64554
2014-04-28 22:58:46pitrousetstatus: open -> closed
resolution: fixed
messages: + msg217438

stage: patch review -> resolved
2014-04-28 22:58:20python-devsetnosy: + python-dev
messages: + msg217437
2014-04-03 20:14:36skrahsetnosy: - skrah
2014-02-24 13:33:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg212094
2014-02-15 15:41:58ezio.melottisetnosy: + ezio.melotti
2014-01-24 15:03:27larrysetmessages: + msg209090
2014-01-24 14:51:45brett.cannonsetmessages: + msg209089
2014-01-24 03:19:05Arfreversetfiles: - python-warnings.patch
2014-01-24 03:17:49Arfreversetfiles: + python-warnings.patch

messages: + msg209031
2014-01-24 02:52:24Arfreversetdependencies: + Use test.script_helper.assert_python_ok() instead of subprocess.* in test.test_warnings
2014-01-24 00:05:35pitrousetmessages: + msg209028
2014-01-24 00:02:41larrysetmessages: + msg209026
2014-01-23 23:30:24pitrousetmessages: + msg209022
2014-01-23 23:19:14pitrousetmessages: + msg209018
2014-01-23 09:06:05Arfreversetstage: needs patch -> patch review
2014-01-23 08:59:42Arfreversetfiles: + python-warnings.patch

nosy: + larry
messages: + msg208886

keywords: + patch
2014-01-22 22:07:46pitrousetversions: + Python 3.5, - Python 2.7, Python 3.3, Python 3.4
nosy: + brett.cannon

messages: + msg208856

type: behavior -> enhancement
stage: needs patch
2014-01-22 21:41:46Arfrevercreate