diff options
| author | Brett Cannon <bcannon@gmail.com> | 2010-01-14 20:00:28 (GMT) | 
|---|---|---|
| committer | Brett Cannon <bcannon@gmail.com> | 2010-01-14 20:00:28 (GMT) | 
| commit | 3ffa43db4892d3a836c63911c5a13a8be5670fa5 (patch) | |
| tree | 5b28b121ee874b1a7341b0cf50fdcec777919e7b /Python/_warnings.c | |
| parent | efdddd3370fc646836b6113247159846734fc129 (diff) | |
| download | cpython-3ffa43db4892d3a836c63911c5a13a8be5670fa5.zip cpython-3ffa43db4892d3a836c63911c5a13a8be5670fa5.tar.gz cpython-3ffa43db4892d3a836c63911c5a13a8be5670fa5.tar.bz2 | |
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.
Diffstat (limited to 'Python/_warnings.c')
| -rw-r--r-- | Python/_warnings.c | 30 | 
1 files changed, 18 insertions, 12 deletions
| diff --git a/Python/_warnings.c b/Python/_warnings.c index 96bb049..f3b2286 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -839,31 +839,37 @@ create_filter(PyObject *category, const char *action)  static PyObject *  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; +      if (filters == NULL)          return NULL; -    PyList_SET_ITEM(filters, 0, -                    create_filter(PyExc_DeprecationWarning, "ignore")); -    PyList_SET_ITEM(filters, 1, +    if (!Py_Py3kWarningFlag) { +        PyList_SET_ITEM(filters, pos++, +                        create_filter(PyExc_DeprecationWarning, "ignore")); +    } +    PyList_SET_ITEM(filters, pos++,                      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)          bytes_action = "error";      else if (Py_BytesWarningFlag)          bytes_action = "default";      else          bytes_action = "ignore"; -    PyList_SET_ITEM(filters, 3, create_filter(PyExc_BytesWarning, +    PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning,                      bytes_action)); -    if (PyList_GET_ITEM(filters, 0) == NULL || -        PyList_GET_ITEM(filters, 1) == NULL || -        PyList_GET_ITEM(filters, 2) == NULL || -        PyList_GET_ITEM(filters, 3) == NULL) { -        Py_DECREF(filters); -        return NULL; +    for (x = 0; x < pos; x += 1) { +        if (PyList_GET_ITEM(filters, x) == NULL) { +            Py_DECREF(filters); +            return NULL; +        }      }      return filters; | 
