Deprecate SupportsUnknownEnumValues on Message reflection. Use FieldDescriptor or EnumDescriptor instead.

PiperOrigin-RevId: 514618684
pull/12161/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 51f22eb334
commit 0b9134bb4e
  1. 2
      .github/workflows/codespell.yml
  2. 5
      python/google/protobuf/pyext/map_container.cc
  3. 2
      python/google/protobuf/pyext/message.cc
  4. 4
      python/google/protobuf/pyext/repeated_scalar_container.cc
  5. 6
      src/google/protobuf/generated_message_reflection.cc
  6. 2
      src/google/protobuf/message.h
  7. 2
      src/google/protobuf/text_format.cc

@ -24,4 +24,4 @@ jobs:
with:
check_filenames: true
skip: ./.git,./third_party,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml
ignore_words_list: "alow,alse,atleast,ba,chec,cleare,copyable,cloneable,crate,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy"
ignore_words_list: "alow,alse,atleast,ba,chec,cleare,copyable,cloneable,crate,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy,cleary"

@ -437,7 +437,10 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
self->version++;
}
if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
if (!PythonToMapValueRef(self, v,
!self->parent_field_descriptor->message_type()
->map_value()
->legacy_enum_field_treated_as_closed(),
&value)) {
return -1;
}

@ -2300,7 +2300,7 @@ int InternalSetNonOneofScalar(
}
case FieldDescriptor::CPPTYPE_ENUM: {
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
if (reflection->SupportsUnknownEnumValues()) {
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
reflection->SetEnumValue(message, field_descriptor, value);
} else {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();

@ -151,7 +151,7 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
}
case FieldDescriptor::CPPTYPE_ENUM: {
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
if (reflection->SupportsUnknownEnumValues()) {
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
reflection->SetRepeatedEnumValue(message, field_descriptor, index,
value);
} else {
@ -376,7 +376,7 @@ PyObject* Append(RepeatedScalarContainer* self, PyObject* item) {
}
case FieldDescriptor::CPPTYPE_ENUM: {
PROTOBUF_CHECK_GET_INT32(item, value, nullptr);
if (reflection->SupportsUnknownEnumValues()) {
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
reflection->AddEnumValue(message, field_descriptor, value);
} else {
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();

@ -1540,10 +1540,6 @@ bool IsIndexInHasBitSet(const uint32_t* has_bit_set, uint32_t has_bit_index) {
static_cast<uint32_t>(1)) != 0;
}
bool CreateUnknownEnumValues(const FileDescriptor* file) {
return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
}
void CheckInOrder(const FieldDescriptor* field, uint32_t* last) {
*last = *last <= static_cast<uint32_t>(field->number())
? static_cast<uint32_t>(field->number())
@ -2486,7 +2482,7 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber(
}
bool Reflection::SupportsUnknownEnumValues() const {
return CreateUnknownEnumValues(descriptor_->file());
return descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
}
// ===================================================================

@ -118,6 +118,7 @@
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/port.h"
#include "absl/base/attributes.h"
#include "absl/base/call_once.h"
#include "absl/base/casts.h"
#include "absl/functional/function_ref.h"
@ -961,6 +962,7 @@ class PROTOBUF_EXPORT Reflection final {
// reflection->SetEnumValue(message, field, new_value);
// }
// }
ABSL_DEPRECATED("Use EnumDescriptor::is_closed instead.")
bool SupportsUnknownEnumValues() const;
// Returns the MessageFactory associated with this message. This can be

@ -918,7 +918,7 @@ class TextFormat::Parser::ParserImpl {
if (enum_value == nullptr) {
if (int_value != kint64max &&
reflection->SupportsUnknownEnumValues()) {
!field->legacy_enum_field_treated_as_closed()) {
SET_FIELD(EnumValue, int_value);
return true;
} else if (!allow_unknown_enum_) {

Loading…
Cancel
Save