Skip to content

Commit

Permalink
Breaking change in 26 release: Remove msg.UnknownFields() support in …
Browse files Browse the repository at this point in the history
…pure python and cpp extension.

Users should use the add-on unknown_fields.py support.
Old usage example:
unknown_field_set = msg.UnknownFields()

New usage should be:
from google.protobuf import unknown_fields
unknown_field_set = unknown_fields.UnknownFieldSet(msg)
PiperOrigin-RevId: 589969095
  • Loading branch information
anandolee authored and copybara-github committed Dec 11, 2023
1 parent e35cf10 commit 0eac77c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
12 changes: 3 additions & 9 deletions python/google/protobuf/internal/python_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,15 +1385,9 @@ def _Clear(self):


def _UnknownFields(self):
warnings.warn(
'message.UnknownFields() is deprecated. Please use the add one '
'feature unknown_fields.UnknownFieldSet(message) in '
'unknown_fields.py instead.'
)
if self._unknown_field_set is None: # pylint: disable=protected-access
# pylint: disable=protected-access
self._unknown_field_set = containers.UnknownFieldSet()
return self._unknown_field_set # pylint: disable=protected-access
raise NotImplementedError('Please use the add-on feaure '
'unknown_fields.UnknownFieldSet(message) in '
'unknown_fields.py instead.')


def _DiscardUnknownFields(self):
Expand Down
15 changes: 5 additions & 10 deletions python/google/protobuf/pyext/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2346,16 +2346,11 @@ static PyObject* GetExtensionDict(CMessage* self, void *closure) {
}

static PyObject* GetUnknownFields(CMessage* self) {
PyErr_Warn(nullptr,
"message.UnknownFields() is deprecated. Please use the "
"add one feature unknown_fields.UnknownFieldSet(message) in "
"unknown_fields.py instead.");
if (self->unknown_field_set == nullptr) {
self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
} else {
Py_INCREF(self->unknown_field_set);
}
return self->unknown_field_set;
PyErr_Format(PyExc_NotImplementedError,
"Please use the add-on feature "
"unknown_fields.UnknownFieldSet(message) in "
"unknown_fields.py instead.");
return nullptr;
}

static PyGetSetDef Getters[] = {
Expand Down

0 comments on commit 0eac77c

Please sign in to comment.