make bytearray work (again) (#16691)
fix is pretty simple, just check if the type is bytearray and get the bytes if it is
addresses issue: https://github.com/protocolbuffers/protobuf/issues/15911
Closes #16691
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/16691 from jensbjorgensen:main 6249e629d7db2f8ee900917798c97fb704abf4a2
PiperOrigin-RevId: 642623917
diff --git a/python/message.c b/python/message.c
index 8d91b0f..327eb2e 100644
--- a/python/message.c
+++ b/python/message.c
@@ -1329,6 +1329,9 @@
int err = PyBytes_AsStringAndSize(bytes, &buf, &size);
(void)err;
assert(err >= 0);
+ } else if (PyByteArray_Check(arg)) {
+ buf = PyByteArray_AS_STRING(arg);
+ size = PyByteArray_GET_SIZE(arg);
} else if (PyBytes_AsStringAndSize(arg, &buf, &size) < 0) {
return NULL;
}