summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-12-02 07:26:14 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-12-02 07:26:14 (GMT)
commit0b2cacb42a7a3a79c1d5c491c584f57aa5c82417 (patch)
tree146cccf1d3df541b76a239ff85fb960f1389105d /Objects
parent5d64858ac8a226760785246bbc1c836b9fcb7f77 (diff)
parent83cf99d733acb49c70dd9548eeccfc724e707531 (diff)
downloadcpython-0b2cacb42a7a3a79c1d5c491c584f57aa5c82417.zip
cpython-0b2cacb42a7a3a79c1d5c491c584f57aa5c82417.tar.gz
cpython-0b2cacb42a7a3a79c1d5c491c584f57aa5c82417.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.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 6dc9f13..a5b9feb 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3039,6 +3039,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. */
@@ -3078,13 +3085,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);
}