Kaydet (Commit) 3ffa43db authored tarafından Brett Cannon's avatar Brett Cannon

The silencing of DeprecationWarning was not taking -3 into consideration. Since

Py3K warnings are DeprecationWarning by default this was causing -3 to
essentially be a no-op. Now DeprecationWarning is only silenced if -3 is not
used.

Closes issue #7700. Thanks Ezio Melotti and Florent Xicluna for patch help.
üst efdddd33
...@@ -383,8 +383,11 @@ except ImportError: ...@@ -383,8 +383,11 @@ except ImportError:
# Module initialization # Module initialization
_processoptions(sys.warnoptions) _processoptions(sys.warnoptions)
if not _warnings_defaults: if not _warnings_defaults:
for cls in (DeprecationWarning, PendingDeprecationWarning, ImportWarning): silence = [ImportWarning, PendingDeprecationWarning]
simplefilter("ignore", category=cls, append=True) if not sys.py3kwarning: # Don't silence DeprecationWarning if -3 was used.
silence.append(DeprecationWarning)
for cls in silence:
simplefilter("ignore", category=cls)
bytes_warning = sys.flags.bytes_warning bytes_warning = sys.flags.bytes_warning
if bytes_warning > 1: if bytes_warning > 1:
bytes_action = "error" bytes_action = "error"
......
...@@ -21,7 +21,8 @@ Core and Builtins ...@@ -21,7 +21,8 @@ Core and Builtins
values. Also fix a number of bugs in dtoa.c that could lead to values. Also fix a number of bugs in dtoa.c that could lead to
incorrectly rounded results when converting strings to floats. incorrectly rounded results when converting strings to floats.
- Issue #7319: Silence DeprecationWarning by default. - Issue #7319, #7770: Silence DeprecationWarning by default when -3 is not
used.
- Issue #2335: Backport set literals syntax from Python 3.x. - Issue #2335: Backport set literals syntax from Python 3.x.
......
...@@ -839,31 +839,37 @@ create_filter(PyObject *category, const char *action) ...@@ -839,31 +839,37 @@ create_filter(PyObject *category, const char *action)
static PyObject * static PyObject *
init_filters(void) init_filters(void)
{ {
PyObject *filters = PyList_New(4); // Don't silence DeprecationWarning if -3 was used.
PyObject *filters = PyList_New(Py_Py3kWarningFlag ? 3 : 4);
unsigned int pos = 0; // Post-incremented in each use.
unsigned int x;
const char *bytes_action; const char *bytes_action;
if (filters == NULL) if (filters == NULL)
return NULL; return NULL;
PyList_SET_ITEM(filters, 0, if (!Py_Py3kWarningFlag) {
create_filter(PyExc_DeprecationWarning, "ignore")); PyList_SET_ITEM(filters, pos++,
PyList_SET_ITEM(filters, 1, create_filter(PyExc_DeprecationWarning, "ignore"));
}
PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_PendingDeprecationWarning, "ignore")); create_filter(PyExc_PendingDeprecationWarning, "ignore"));
PyList_SET_ITEM(filters, 2, create_filter(PyExc_ImportWarning, "ignore")); PyList_SET_ITEM(filters, pos++,
create_filter(PyExc_ImportWarning, "ignore"));
if (Py_BytesWarningFlag > 1) if (Py_BytesWarningFlag > 1)
bytes_action = "error"; bytes_action = "error";
else if (Py_BytesWarningFlag) else if (Py_BytesWarningFlag)
bytes_action = "default"; bytes_action = "default";
else else
bytes_action = "ignore"; bytes_action = "ignore";
PyList_SET_ITEM(filters, 3, create_filter(PyExc_BytesWarning, PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning,
bytes_action)); bytes_action));
if (PyList_GET_ITEM(filters, 0) == NULL || for (x = 0; x < pos; x += 1) {
PyList_GET_ITEM(filters, 1) == NULL || if (PyList_GET_ITEM(filters, x) == NULL) {
PyList_GET_ITEM(filters, 2) == NULL || Py_DECREF(filters);
PyList_GET_ITEM(filters, 3) == NULL) { return NULL;
Py_DECREF(filters); }
return NULL;
} }
return filters; return filters;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment