diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-06 20:29:29 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-06 20:29:29 (GMT) |
commit | febc3320563bf597e186ebce75abdac2926ceeb6 (patch) | |
tree | 1360725b7e65af72348ed78687257249ccf1d36e /Objects | |
parent | d73c31899e88aa5a1cc28f288cc70a35f2a196c2 (diff) | |
download | cpython-febc3320563bf597e186ebce75abdac2926ceeb6.zip cpython-febc3320563bf597e186ebce75abdac2926ceeb6.tar.gz cpython-febc3320563bf597e186ebce75abdac2926ceeb6.tar.bz2 |
Issue #26754: Undocumented support of general bytes-like objects
as path in compile() and similar functions is now deprecated.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 0932f35..2d31c70 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3837,7 +3837,13 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr) output = arg; Py_INCREF(output); } - else if (PyObject_CheckBuffer(arg)) { + else if (PyBytes_Check(arg) || PyObject_CheckBuffer(arg)) { + if (!PyBytes_Check(arg) && + PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "path should be string or bytes, not %.200s", + Py_TYPE(arg)->tp_name)) { + return 0; + } arg = PyBytes_FromObject(arg); if (!arg) return 0; @@ -3846,11 +3852,6 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr) Py_DECREF(arg); if (!output) return 0; - if (!PyUnicode_Check(output)) { - Py_DECREF(output); - PyErr_SetString(PyExc_TypeError, "decoder failed to return unicode"); - return 0; - } } else { PyErr_Format(PyExc_TypeError, |