diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-02 07:24:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-02 07:24:06 (GMT) |
commit | 83cf99d733acb49c70dd9548eeccfc724e707531 (patch) | |
tree | 2b0f3a1cf6d3fc28556ad920f10879d6bb69f5d9 /Objects | |
parent | 9d98c9bf42412e05b5352329c6f141df49dd8df7 (diff) | |
download | cpython-83cf99d733acb49c70dd9548eeccfc724e707531.zip cpython-83cf99d733acb49c70dd9548eeccfc724e707531.tar.gz cpython-83cf99d733acb49c70dd9548eeccfc724e707531.tar.bz2 |
Issue #20335: bytes constructor now raises TypeError when encoding or errors
is specified with non-string argument. Based on patch by Renaud Blanch.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 4a8561c..a3ccbcf 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2503,6 +2503,13 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return new; } + /* If it's not unicode, there can't be encoding or errors */ + if (encoding != NULL || errors != NULL) { + PyErr_SetString(PyExc_TypeError, + "encoding or errors without a string argument"); + return NULL; + } + /* We'd like to call PyObject_Bytes here, but we need to check for an integer argument before deferring to PyBytes_FromObject, something PyObject_Bytes doesn't do. */ @@ -2544,13 +2551,6 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return new; } - /* If it's not unicode, there can't be encoding or errors */ - if (encoding != NULL || errors != NULL) { - PyErr_SetString(PyExc_TypeError, - "encoding or errors without a string argument"); - return NULL; - } - return PyBytes_FromObject(x); } |