diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-06 23:29:29 +0300 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-06 23:29:29 +0300 |
| commit | febc3320563bf597e186ebce75abdac2926ceeb6 (patch) | |
| tree | 1360725b7e65af72348ed78687257249ccf1d36e /Objects/unicodeobject.c | |
| parent | d73c31899e88aa5a1cc28f288cc70a35f2a196c2 (diff) | |
| download | cpython-git-febc3320563bf597e186ebce75abdac2926ceeb6.tar.gz | |
Issue #26754: Undocumented support of general bytes-like objects
as path in compile() and similar functions is now deprecated.
Diffstat (limited to 'Objects/unicodeobject.c')
| -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 0932f35b76..2d31c700de 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, |
