mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
now return an instance of corresponding subclass.
This commit is contained in:
parent
cf8b42e904
commit
0855e706aa
5 changed files with 50 additions and 10 deletions
|
|
@ -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__,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue