Skip to content

Commit 4ebba68

Browse files
anandoleecopybara-github
authored andcommitted
BREAKING CHANGE in v26: Remove RegisterExtension in message class
PiperOrigin-RevId: 595989309
1 parent 7bbc0b6 commit 4ebba68

4 files changed

Lines changed: 0 additions & 46 deletions

File tree

python/google/protobuf/internal/python_message.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,6 @@ def _AddPropertiesForExtensions(descriptor, cls):
779779
pool = descriptor.file.pool
780780

781781
def _AddStaticMethods(cls):
782-
# TODO: This probably needs to be thread-safe(?)
783-
def RegisterExtension(field_descriptor):
784-
field_descriptor.containing_type = cls.DESCRIPTOR
785-
# TODO: Use cls.MESSAGE_FACTORY.pool when available.
786-
# pylint: disable=protected-access
787-
cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(field_descriptor)
788-
_AttachFieldHelpers(cls, field_descriptor)
789-
cls.RegisterExtension = staticmethod(RegisterExtension)
790-
791782
def FromString(s):
792783
message = cls()
793784
message.MergeFromString(s)

python/google/protobuf/message.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ def ByteSize(self):
340340
def FromString(cls, s):
341341
raise NotImplementedError
342342

343-
# TODO: Remove it in OSS
344-
@staticmethod
345-
def RegisterExtension(field_descriptor):
346-
raise NotImplementedError
347-
348343
def _SetListener(self, message_listener):
349344
"""Internal method used by the protocol message implementation.
350345
Clients should not call this directly.

python/google/protobuf/pyext/message.cc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,32 +1855,6 @@ static PyObject* ByteSize(CMessage* self, PyObject* args) {
18551855
return PyLong_FromLong(self->message->ByteSizeLong());
18561856
}
18571857

1858-
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
1859-
const FieldDescriptor* descriptor =
1860-
GetExtensionDescriptor(extension_handle);
1861-
if (descriptor == nullptr) {
1862-
return nullptr;
1863-
}
1864-
if (!PyObject_TypeCheck(cls, CMessageClass_Type)) {
1865-
PyErr_Format(PyExc_TypeError, "Expected a message class, got %s",
1866-
cls->ob_type->tp_name);
1867-
return nullptr;
1868-
}
1869-
CMessageClass *message_class = reinterpret_cast<CMessageClass*>(cls);
1870-
if (message_class == nullptr) {
1871-
return nullptr;
1872-
}
1873-
// If the extension was already registered, check that it is the same.
1874-
const FieldDescriptor* existing_extension =
1875-
message_class->py_message_factory->pool->pool->FindExtensionByNumber(
1876-
descriptor->containing_type(), descriptor->number());
1877-
if (existing_extension != nullptr && existing_extension != descriptor) {
1878-
PyErr_SetString(PyExc_ValueError, "Double registration of Extensions");
1879-
return nullptr;
1880-
}
1881-
Py_RETURN_NONE;
1882-
}
1883-
18841858
static PyObject* SetInParent(CMessage* self, PyObject* args) {
18851859
AssureWritable(self);
18861860
Py_RETURN_NONE;
@@ -2391,8 +2365,6 @@ static PyMethodDef Methods[] = {
23912365
"Merges a serialized message into the current message."},
23922366
{"ParseFromString", (PyCFunction)ParseFromString, METH_O,
23932367
"Parses a serialized message into the current message."},
2394-
{"RegisterExtension", (PyCFunction)RegisterExtension, METH_O | METH_CLASS,
2395-
"Registers an extension with the current message."},
23962368
{"SerializePartialToString", (PyCFunction)SerializePartialToString,
23972369
METH_VARARGS | METH_KEYWORDS,
23982370
"Serializes the message to a string, even if it isn't initialized."},

python/google/protobuf/pyext/message.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs);
229229

230230
PyObject* MergeFrom(CMessage* self, PyObject* arg);
231231

232-
// This method does not do anything beyond checking that no other extension
233-
// has been registered with the same field number on this class.
234-
PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle);
235-
236232
// Get a field from a message.
237233
PyObject* GetFieldValue(CMessage* self,
238234
const FieldDescriptor* field_descriptor);

0 commit comments

Comments
 (0)