Issue 20355: -W command line options should have higher priority than PYTHONWARNINGS environmental variable
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) * ![]() |
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) * ![]() |
Date: 2014-01-22 22:07 | |
Agreed. |
|||
| msg208886 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2014-01-24 14:51 | |
I agree with Antoine; this can wait for Python 3.5. |
|||
| msg209090 - (view) | Author: Larry Hastings (larry) * ![]() |
Date: 2014-01-24 15:03 | |
Okay, then yes, let's save this for 3.5. Thanks! |
|||
| msg212094 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
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) ![]() |
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) * ![]() |
Date: 2014-04-28 22:58 | |
Committed. Thanks, Arfrever! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:57 | admin | set | github: 64554 |
| 2014-04-28 22:58:46 | pitrou | set | status: open -> closed resolution: fixed messages: + msg217438 stage: patch review -> resolved |
| 2014-04-28 22:58:20 | python-dev | set | nosy:
+ python-dev messages: + msg217437 |
| 2014-04-03 20:14:36 | skrah | set | nosy:
- skrah |
| 2014-02-24 13:33:03 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg212094 |
| 2014-02-15 15:41:58 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2014-01-24 15:03:27 | larry | set | messages: + msg209090 |
| 2014-01-24 14:51:45 | brett.cannon | set | messages: + msg209089 |
| 2014-01-24 03:19:05 | Arfrever | set | files: - python-warnings.patch |
| 2014-01-24 03:17:49 | Arfrever | set | files:
+ python-warnings.patch messages: + msg209031 |
| 2014-01-24 02:52:24 | Arfrever | set | dependencies: + Use test.script_helper.assert_python_ok() instead of subprocess.* in test.test_warnings |
| 2014-01-24 00:05:35 | pitrou | set | messages: + msg209028 |
| 2014-01-24 00:02:41 | larry | set | messages: + msg209026 |
| 2014-01-23 23:30:24 | pitrou | set | messages: + msg209022 |
| 2014-01-23 23:19:14 | pitrou | set | messages: + msg209018 |
| 2014-01-23 09:06:05 | Arfrever | set | stage: needs patch -> patch review |
| 2014-01-23 08:59:42 | Arfrever | set | files:
+ python-warnings.patch nosy:
+ larry keywords: + patch |
| 2014-01-22 22:07:46 | pitrou | set | versions:
+ Python 3.5, - Python 2.7, Python 3.3, Python 3.4 nosy: + brett.cannon messages: + msg208856 type: behavior -> enhancement |
| 2014-01-22 21:41:46 | Arfrever | create | |

