Skip to content

Commit

Permalink
Raise warings for message.UnknownFields() usages and navigate to the …
Browse files Browse the repository at this point in the history
…new add

one API

The message.UnknownFields() support will be removed soon

PiperOrigin-RevId: 553871453
  • Loading branch information
anandolee authored and copybara-github committed Aug 4, 2023
1 parent f607b66 commit c988759
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/google/protobuf/internal/python_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@
from io import BytesIO
import struct
import sys
import warnings
import weakref

from google.protobuf import descriptor as descriptor_mod
from google.protobuf import message as message_mod
from google.protobuf import text_format
# We use "as" to avoid name collisions with variables.
from google.protobuf.internal import api_implementation
from google.protobuf.internal import containers
Expand All @@ -66,9 +70,6 @@
from google.protobuf.internal import type_checkers
from google.protobuf.internal import well_known_types
from google.protobuf.internal import wire_format
from google.protobuf import descriptor as descriptor_mod
from google.protobuf import message as message_mod
from google.protobuf import text_format

_FieldDescriptor = descriptor_mod.FieldDescriptor
_AnyFullTypeName = 'google.protobuf.Any'
Expand Down Expand Up @@ -1361,6 +1362,11 @@ def _Clear(self):


def _UnknownFields(self):
warnings.warn(
'message.UnknownFields() is deprecated. Please use the add one '
'feature message_factotry.UnknownFieldSet(message) in '
'message_factotry.py instead.'
)
if self._unknown_field_set is None: # pylint: disable=protected-access
# pylint: disable=protected-access
self._unknown_field_set = containers.UnknownFieldSet()
Expand Down
4 changes: 4 additions & 0 deletions python/google/protobuf/pyext/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,10 @@ 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 message_factotry.UnknownFieldSet(message) in "
"message_factotry.py instead.");
if (self->unknown_field_set == nullptr) {
self->unknown_field_set = unknown_fields::NewPyUnknownFields(self);
} else {
Expand Down

0 comments on commit c988759

Please sign in to comment.