mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-129349: Accept bytes in bytes.fromhex()/bytearray.fromhex() (#129844)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
405a2d74cb
commit
e0637cebe5
8 changed files with 90 additions and 69 deletions
|
@ -2533,7 +2533,7 @@ bytearray_splitlines_impl(PyByteArrayObject *self, int keepends)
|
|||
@classmethod
|
||||
bytearray.fromhex
|
||||
|
||||
string: unicode
|
||||
string: object
|
||||
/
|
||||
|
||||
Create a bytearray object from a string of hexadecimal numbers.
|
||||
|
@ -2543,8 +2543,8 @@ Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
|
|||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
bytearray_fromhex_impl(PyTypeObject *type, PyObject *string)
|
||||
/*[clinic end generated code: output=8f0f0b6d30fb3ba0 input=f033a16d1fb21f48]*/
|
||||
bytearray_fromhex(PyTypeObject *type, PyObject *string)
|
||||
/*[clinic end generated code: output=da84dc708e9c4b36 input=7e314e5b2d7ab484]*/
|
||||
{
|
||||
PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
|
||||
if (type != &PyByteArray_Type && result != NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue