protobuf: Improve error message while constructing messages in Python.

"Value is not iterable" is sometimes not that helpful. Lets at least mention the field name.

PiperOrigin-RevId: 489485451
pull/11022/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 280439822a
commit b141bf9b1e
  1. 6
      python/google/protobuf/pyext/message.cc

@ -1100,7 +1100,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
reinterpret_cast<RepeatedCompositeContainer*>(container.get());
ScopedPyObjectPtr iter(PyObject_GetIter(value));
if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
PyErr_Format(PyExc_TypeError, "Value of field '%s' must be iterable",
descriptor->name().c_str());
return -1;
}
ScopedPyObjectPtr next;
@ -1129,7 +1130,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
reinterpret_cast<RepeatedScalarContainer*>(container.get());
ScopedPyObjectPtr iter(PyObject_GetIter(value));
if (iter == nullptr) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
PyErr_Format(PyExc_TypeError, "Value of field '%s' must be iterable",
descriptor->name().c_str());
return -1;
}
ScopedPyObjectPtr next;

Loading…
Cancel
Save