summaryrefslogtreecommitdiff
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-01 17:22:31 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-01 17:22:31 +0300
commit0855e706aa7fed842e18b0ce14e18d6574318643 (patch)
tree2fa36bacf92f87ea7361122e8a49d8690c7d5e1b /Objects/bytearrayobject.c
parentcf8b42e9043766338c0b16d0dca3ed5ca70a812d (diff)
downloadcpython-git-0855e706aa7fed842e18b0ce14e18d6574318643.tar.gz
Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
now return an instance of corresponding subclass.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index b7dfd6f20f..85990e0be4 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1968,7 +1968,6 @@ bytearray_splitlines_impl(PyByteArrayObject *self, int keepends)
@classmethod
bytearray.fromhex
- cls: self(type="PyObject*")
string: unicode
/
@@ -1979,10 +1978,15 @@ Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
[clinic start generated code]*/
static PyObject *
-bytearray_fromhex_impl(PyObject*cls, PyObject *string)
-/*[clinic end generated code: output=df3da60129b3700c input=907bbd2d34d9367a]*/
+bytearray_fromhex_impl(PyTypeObject *type, PyObject *string)
+/*[clinic end generated code: output=8f0f0b6d30fb3ba0 input=f033a16d1fb21f48]*/
{
- return _PyBytes_FromHex(string, 1);
+ PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
+ if (type != &PyByteArray_Type && result != NULL) {
+ Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type,
+ result, NULL));
+ }
+ return result;
}
PyDoc_STRVAR(hex__doc__,