Message 91483 - Python tracker (original) (raw)

The documentation for PyBytes_FromObject states:

.. cfunction:: PyObject* PyBytes_FromObject(PyObject *o)

Return the bytes representation of object o that implements the buffer protocol.

However, there exists a special-case for integer object in PyBytes_FromObject that makes the function return a null-initialized bytes object. Currently, this is only used for handling `bytes(10)'.

I don't like changing APIs after a stable release, but I believe this behaviour is error-prone and surprising (and darn right annoying even). So, I believe the special-case should be made specific to the bytes constructor.

Thus, here is the fine patch.