Skip to content

Commit 9f22f63

Browse files
Add Python deprecation warnings for Descriptor Label.
PiperOrigin-RevId: 756954086
1 parent 0cdbc0b commit 9f22f63

File tree

3 files changed

+404
-237
lines changed

3 files changed

+404
-237
lines changed

python/descriptor.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,20 @@ 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+
10571068
static PyObject* PyUpb_FieldDescriptor_GetLabel(PyUpb_DescriptorBase* self,
10581069
void* closure) {
1070+
WarnDeprecatedLabel();
10591071
return PyLong_FromLong(upb_FieldDef_Label(self->def));
10601072
}
10611073

0 commit comments

Comments
 (0)