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.

Author vstinner
Recipients barry, eric.snow, ncoghlan, vstinner
Date 2017-11-16.02:04:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1510797872.08.0.213398074469.issue32030@psf.upfronthosting.co.za>
In-reply-to
Content
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 :-)
History
Date User Action Args
2017-11-16 02:04:32vstinnersetrecipients: + vstinner, barry, ncoghlan, eric.snow
2017-11-16 02:04:32vstinnersetmessageid: <1510797872.08.0.213398074469.issue32030@psf.upfronthosting.co.za>
2017-11-16 02:04:32vstinnerlinkissue32030 messages
2017-11-16 02:04:31vstinnercreate