[issue32030] PEP 432: Rewrite Py_Main()

Nick Coghlan report at bugs.python.org
Tue Nov 14 21:18:56 EST 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

While it doesn't necessarily need to be in this patch, something else I recently realised (by breaking it *cough* [1]) is that the interaction between our command line options and our environment variables isn't really clearly defined anywhere.

https://github.com/python/cpython/commit/d7ac06126db86f76ba92cbca4cb702852a321f78 restored the handling of simple on/off toggles as "toggle enabled = env var is set OR CLI flag is passed", but I noticed the other day that the interaction between PYTHONWARNINGS, the `-W` option, sys.warnoptions, and _warnings.filters is a bit confusing:

```
$ PYTHONWARNINGS=always,default python3 -Wignore -Wonce
Python 3.6.2 (default, Oct  2 2017, 16:51:32) 
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, _warnings
>>> sys.warnoptions
['always', 'default', 'ignore', 'once']
>>> [f[0] for f in _warnings.filters[:4]]
['once', 'ignore', 'default', 'always']
```

The ordering makes *sense* (where sys.warnoptions just lists filter definitions in the order they're given, and later filters take priority over earlier ones, just as they do for any "warnings.filterwarnings" call), but it isn't immediately intuitive (since the outcome relies on filters being prepended by default).

That said, I've checked and the current warnings configuration behaviour *is* explicitly covered by the test suite (in https://github.com/python/cpython/blob/master/Lib/test/test_warnings/__init__.py), so a passing test suite provides confidence we haven't broken anything on that front.

[1] https://bugs.python.org/issue31845

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32030>
_______________________________________


More information about the Python-bugs-list mailing list