Skip to content

Commit 0a8ff55

Browse files
anandoleecopybara-github
authored andcommitted
Breaking change: Remove deprecated FieldDescriptor.label
https://protobuf.dev/news/2025-09-19/#python-remove-apis PiperOrigin-RevId: 836922631
1 parent 8d6438e commit 0a8ff55

File tree

5 files changed

+2
-48
lines changed

5 files changed

+2
-48
lines changed

python/descriptor.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,23 +1054,6 @@ static PyObject* PyUpb_FieldDescriptor_GetCppType(PyUpb_DescriptorBase* self,
10541054
return PyLong_FromLong(cpp_types[upb_FieldDef_CType(self->def)]);
10551055
}
10561056

1057-
static void WarnDeprecatedLabel(void) {
1058-
static int deprecated_label_count = 100;
1059-
if (deprecated_label_count > 0) {
1060-
--deprecated_label_count;
1061-
PyErr_WarnEx(
1062-
PyExc_DeprecationWarning,
1063-
"label() is deprecated. Use is_required() or is_repeated() instead.",
1064-
3);
1065-
}
1066-
}
1067-
1068-
static PyObject* PyUpb_FieldDescriptor_GetLabel(PyUpb_DescriptorBase* self,
1069-
void* closure) {
1070-
WarnDeprecatedLabel();
1071-
return PyLong_FromLong(upb_FieldDef_Label(self->def));
1072-
}
1073-
10741057
static PyObject* PyUpb_FieldDescriptor_IsRequired(PyUpb_DescriptorBase* self,
10751058
void* closure) {
10761059
return PyBool_FromLong(upb_FieldDef_IsRequired(self->def));
@@ -1186,7 +1169,6 @@ static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = {
11861169
{"file", (getter)PyUpb_FieldDescriptor_GetFile, NULL, "File Descriptor"},
11871170
{"type", (getter)PyUpb_FieldDescriptor_GetType, NULL, "Type"},
11881171
{"cpp_type", (getter)PyUpb_FieldDescriptor_GetCppType, NULL, "C++ Type"},
1189-
{"label", (getter)PyUpb_FieldDescriptor_GetLabel, NULL, "Label"},
11901172
{"is_required", (getter)PyUpb_FieldDescriptor_IsRequired, NULL,
11911173
"Is Required"},
11921174
{"is_repeated", (getter)PyUpb_FieldDescriptor_IsRepeated, NULL,

python/google/protobuf/descriptor.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -791,17 +791,6 @@ def type(self):
791791
def type(self, val):
792792
self._type = val
793793

794-
@property
795-
def label(self):
796-
_Deprecated('label property', 'is_required or is_repeated properties')
797-
798-
if (
799-
self._GetFeatures().field_presence
800-
== _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED
801-
):
802-
return FieldDescriptor.LABEL_REQUIRED
803-
return self._label
804-
805794
@property
806795
def is_required(self):
807796
"""Returns if the field is required."""

python/google/protobuf/internal/field_mask_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def testMergeMessageWithoutMapFieldsOrFieldPresence(self):
302302
mask.MergeMessage(src, dst)
303303
# The expected result message.
304304
msg = unittest_no_field_presence_pb2.TestAllTypes()
305-
if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
305+
if field.is_repeated:
306306
repeated_src = getattr(src, field_name)
307307
repeated_msg = getattr(msg, field_name)
308308
if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:

python/google/protobuf/internal/message_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ def testProto3Optional(self):
21302130
if field.name.startswith('optional_'):
21312131
self.assertTrue(field.has_presence)
21322132
for field in unittest_pb2.TestAllTypes.DESCRIPTOR.fields:
2133-
if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
2133+
if field.is_repeated:
21342134
self.assertFalse(field.has_presence)
21352135
else:
21362136
self.assertTrue(field.has_presence)

python/google/protobuf/pyext/descriptor.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -863,22 +863,6 @@ static PyObject* GetCppType(PyBaseDescriptor* self, void* closure) {
863863
return PyLong_FromLong(_GetDescriptor(self)->cpp_type());
864864
}
865865

866-
static void WarnDeprecatedLabel() {
867-
static int deprecated_label_count = 100;
868-
if (deprecated_label_count > 0) {
869-
--deprecated_label_count;
870-
PyErr_WarnEx(
871-
PyExc_DeprecationWarning,
872-
"label() is deprecated. Use is_required() or is_repeated() instead.",
873-
3);
874-
}
875-
}
876-
877-
static PyObject* GetLabel(PyBaseDescriptor* self, void* closure) {
878-
WarnDeprecatedLabel();
879-
return PyLong_FromLong(_GetDescriptor(self)->label());
880-
}
881-
882866
static PyObject* IsRequired(PyBaseDescriptor* self, void* closure) {
883867
return PyBool_FromLong(_GetDescriptor(self)->is_required());
884868
}
@@ -1094,7 +1078,6 @@ static PyGetSetDef Getters[] = {
10941078
{"file", (getter)GetFile, nullptr, "File Descriptor"},
10951079
{"type", (getter)GetType, nullptr, "C++ Type"},
10961080
{"cpp_type", (getter)GetCppType, nullptr, "C++ Type"},
1097-
{"label", (getter)GetLabel, nullptr, "Label"},
10981081
{"is_required", (getter)IsRequired, nullptr, "Is Required"},
10991082
{"is_repeated", (getter)IsRepeated, nullptr, "Is Repeated"},
11001083
{"number", (getter)GetNumber, nullptr, "Number"},

0 commit comments

Comments
 (0)