Breaking change: Raise IndexError for out-of-range indices in RepeatedContainer.pop() in Python upb implementation. Previously, calling pop(index) on a repeated field with an index greater than or equal to the container's length emitted a FutureWarning and clamped the index to the last element, removing and returning the last element instead. It now raises IndexError, consistent with Python's native list.pop() behaviour and the Python protobuf pure-Python and C++ implementations. https://protobuf.dev/news/2026-09-22/#repeatedcontainerpop PiperOrigin-RevId: 1002527165
diff --git a/python/google/protobuf/breaking_changes.h b/python/google/protobuf/breaking_changes.h index 87a651d..901281f 100644 --- a/python/google/protobuf/breaking_changes.h +++ b/python/google/protobuf/breaking_changes.h
@@ -14,10 +14,6 @@ #ifdef PROTOBUF_PY_FUTURE_BREAKING_CHANGES -// Removes non-standard clamping behavior in RepeatedContainer.pop() -// Owner: runze@ -#define PROTOBUF_PY_FUTURE_REMOVE_POP_CLAMP 1 - // Fix PyProto C++ and upb implementations to return NotImplemented in // descriptor container equality checks for unrecognized types. // Owner: runze@ @@ -29,8 +25,6 @@ #else -#define PROTOBUF_PY_FUTURE_REMOVE_POP_CLAMP 0 - #define PROTOBUF_PY_FUTURE_CONTAINER_EQ_RETURNS_NOTIMPLEMENTED 0 #define PROTOBUF_PY_FUTURE_FREEZE_OPTIONS 0
diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index b7157ef..5cb41d8 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py
@@ -1917,10 +1917,6 @@ self.assertEqual([1, 3], [n.bb for n in m.repeated_nested_message]) self.assertEqual(3, m.repeated_nested_message.pop(-1).bb) - @unittest.skipIf( - api_implementation.Type() == 'upb', - "Currently broken in upb, will be fixed in the next breaking release" - ) def testRepeatedPopOutOfBounds(self, message_module): m = message_module.TestAllTypes() m.repeated_int32.extend(range(5))
diff --git a/python/repeated.c b/python/repeated.c index 6be7141..3b34fd2 100644 --- a/python/repeated.c +++ b/python/repeated.c
@@ -13,7 +13,6 @@ #include <stdint.h> #include <string.h> -#include "google/protobuf/breaking_changes.h" #include "python/buffer_convert.h" #include "python/convert.h" #include "python/descriptor.h" @@ -959,13 +958,6 @@ if (!arr) return NULL; size_t size = upb_Array_Size(arr); if (index < 0) index += size; -#if PROTOBUF_PY_FUTURE_REMOVE_POP_CLAMP -#else - if (index >= size) { - PyErr_WarnEx(PyExc_FutureWarning, "pop index out of range", 1); - index = size - 1; - } -#endif // PROTOBUF_PY_FUTURE_REMOVE_POP_CLAMP PyObject* ret = PyUpb_RepeatedContainer_Item(_self, index); if (!ret) return NULL; upb_Array_Delete(self->ptr.arr, index, 1);