When DeprecationWarning was silenced by default, it also silenced any use of -Q
by default as well. This change fixes that by treating -Q like -3 when it comes
to DeprecationWarning; using it causes the silencing to not occur.
Fixes issue #7319.
diff --git a/Python/_warnings.c b/Python/_warnings.c
index bddd44c..1dc2512 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -280,7 +280,7 @@
PyFile_WriteString("\n", f_stderr);
}
else
- _Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename),
+ _Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename),
lineno, 2);
PyErr_Clear();
}
@@ -294,7 +294,7 @@
PyObject *item = Py_None;
const char *action;
int rc;
-
+
if (registry && !PyDict_Check(registry) && (registry != Py_None)) {
PyErr_SetString(PyExc_TypeError, "'registry' must be a dict");
return NULL;
@@ -839,8 +839,9 @@
static PyObject *
init_filters(void)
{
- /* Don't silence DeprecationWarning if -3 was used. */
- PyObject *filters = PyList_New(Py_Py3kWarningFlag ? 3 : 4);
+ /* Don't silence DeprecationWarning if -3 or -Q were used. */
+ PyObject *filters = PyList_New(Py_Py3kWarningFlag ||
+ Py_DivisionWarningFlag ? 3 : 4);
unsigned int pos = 0; /* Post-incremented in each use. */
unsigned int x;
const char *bytes_action;
@@ -848,7 +849,8 @@
if (filters == NULL)
return NULL;
- if (!Py_Py3kWarningFlag) {
+ /* If guard changes, make sure to update 'filters' initialization above. */
+ if (!Py_Py3kWarningFlag && !Py_DivisionWarningFlag) {
PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_DeprecationWarning, "ignore"));
}