Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Feature or enhancement
Proposal:
Currentlyint.from_bytes
takes aPyObject*
and alwaysconverts it to abytes
usingPyObject_Bytes
. When a "bytes-like" object is passed in, such asbytearray
in_pylong
, thePyObject_Bytes
function has to make a newPyBytes*
and copy the data from the bytes-like into it. Utilize the buffer protocol, with a fallback to PyObject_Bytes, to remove that object allocation and copy making the conversion faster.
I think the fallback is needed becausePyObject_Bytes
supports additional methods, such as.__bytes__()
to construct thebytes
, which should remain supported. That means need to keep doingbytes as bytes_obj: object
in Argument Clinic, rather thanbytes as bytes_obj: Py_buffer
.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response