◐ Shell
clean mode source ↗

gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) by vstinner · Pull Request #125581 · python/cpython

I would like to get rid of PyBytes_FromStringAndSize(NULL, size) calls which create an incomplete bytes object, but PyBytes_FromStringAndSize(NULL, 0) doesn't have this issue.

Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) is simpler and a little bit faster than PyBytes_FromStringAndSize(NULL, 0).

In general, I would prefer to make Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) the reference function to get an empty byte string.