Skip to content

Commit 5cdde97

Browse files
Add Python deprecation warnings for Descriptor Label.
PiperOrigin-RevId: 756954086
1 parent cd17890 commit 5cdde97

File tree

5 files changed

+458
-237
lines changed

5 files changed

+458
-237
lines changed

hpb/g3doc/index.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Handle Protobuf - hbp
2+
3+
go/hpb
4+
5+
<!--*
6+
# Document freshness: For more information, see go/fresh-source.
7+
freshness: { owner: 'hongshin' reviewed: '2025-05-14' }
8+
*-->
9+
10+
## What is hpb?
11+
12+
hpb is a C++ Protobuf API that provides a familiar protobuf experience while
13+
hiding internal implementation details. This encapsulation allows for swapping
14+
out the backend without breaking user code. hpb wraps other protobuf
15+
implementations -- currently only upb is supported, but a proto2 C++ backend is
16+
in the early stages.
17+
18+
hpb is designed to be a "free" wrapper, such that it adds no runtime overhead
19+
compared with using the underlying backend directly. The wrapping is all
20+
performed in header files that optimize away at compile time.
21+
22+
hpb is the preferred solution for users who want to use upb protos in a C++
23+
application. Unlike the upb C generated code, hpb provides a stable API and
24+
properly handles naming conflicts. hpb is also far more ergonomic than the upb
25+
generated code.
26+
27+
## Why hpb?
28+
29+
- As mentioned in go/upb, the upb C API is not stable, and not intended for
30+
use in applications. hpb fills this gap.
31+
- upbc gencode can change and break clients at any time. hpb is designed
32+
for user applications inside of g3 and has stronger guarantees of api
33+
stability
34+
- LSCs/cleanups are handled by the Protobuf team - less maintenance burden
35+
- Code will be more readable. Regular C++ method calls vs field accessors. No
36+
need to provide fully qualified names in terra hpb.
37+
- `my_project_MyMessage_set_x` vs `msg.set_x()`
38+
- [planned] Gives a transition path if your team wishes to move from proto2::cpp to upb
39+
via hpb(cpp) -> hpb(upb). All toggled statically with a BUILD flag
40+
- [planned] interop between hpb(upb) and hpb(cpp)
41+
42+
## How can I get access?
43+
44+
hpb is currently in special availability. If you think this would be a good
45+
fit for your team, please reach out to the Protobuf team.
46+

hpb/g3doc/sitemap.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# hpb::
2+
3+
<!--*
4+
# Document freshness: For more information, see go/fresh-source.
5+
freshness: { owner: 'hongshin' reviewed: '2025-05-14' }
6+
*-->
7+
8+
* [Home](/third_party/protobuf/hpb/g3doc/index.md)

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)