Raise warings for message.UnknownFields() usages and navigate to the new add

one API

The message.UnknownFields() support will be removed soon

PiperOrigin-RevId: 553871453
pull/13455/head
Jie Luo 1 year ago committed by Copybara-Service
parent f607b66d9f
commit c988759a9b
  1. 12
      python/google/protobuf/internal/python_message.py
  2. 4
      python/google/protobuf/pyext/message.cc

@ -53,8 +53,12 @@ __author__ = 'robinson@google.com (Will Robinson)'
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
@ -66,9 +70,6 @@ from google.protobuf.internal import message_listener as message_listener_mod
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'
@ -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()

@ -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 {

Loading…
Cancel
Save