The PEP 587 says that PyConfig.warnoptions has the highest priority for warnings options:
https://www.python.org/dev/peps/pep-0587/#priority-and-rules
But in the current implementation, PyConfig.warnoptions has... the lowest priority :-(
Attached PR not only fix the issue but also add tests to ensure that every ways to set warnings options have the expected priority.
Priority of warnings options, lowest to highest:
- any implicit filters added by _warnings.c/warnings.py
- PyConfig.dev_mode: "default" filter
- PYTHONWARNINGS environment variable
- '-W' command line options
- PyConfig.bytes_warning ('-b', '-bb'): "default::BytesWarning"
or "error::BytesWarning" filter
- early PySys_AddWarnOption() calls
- PyConfig.warnoptions