STINNER Victor <victor.stin...@gmail.com> added the comment:

Nick:
"""
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
(...)
>>> sys.warnoptions
['always', 'default', 'ignore', 'once']
>>> [f[0] for f in _warnings.filters[:4]]
['once', 'ignore', 'default', 'always']
"""

IMHO the command line must have the priority over environment variables, since 
environment variables are inherited, whereas the command line can be finely 
tuned *on purpose*. So it's correct, no? It's just that warnoptions gives 
options in the reverse order than the "expected" order, no?

At least, with my commit, if you want to try to change the priority, you just 
have to exchange two lines in pymain_add_warnings_options() :-)

    if (pymain_add_warnings_optlist(&pymain->env_warning_options) < 0) ...
    if (pymain_add_warnings_optlist(&pymain->cmdline.warning_options) < 0) ...

--

By the way, I'm not sure that it was a good idea to expose sys.warnoptions to 
users, but I don't think that we can remove it anymore :-)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32030>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to