Skip to content

Add Python deprecation warnings for Descriptor Label. #21698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions hpb/g3doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Handle Protobuf - hbp

go/hpb

<!--*
# Document freshness: For more information, see go/fresh-source.
freshness: { owner: 'hongshin' reviewed: '2025-05-14' }
*-->

## What is hpb?

hpb is a C++ Protobuf API that provides a familiar protobuf experience while
hiding internal implementation details. This encapsulation allows for swapping
out the backend without breaking user code. hpb wraps other protobuf
implementations -- currently only upb is supported, but a proto2 C++ backend is
in the early stages.

hpb is designed to be a "free" wrapper, such that it adds no runtime overhead
compared with using the underlying backend directly. The wrapping is all
performed in header files that optimize away at compile time.

hpb is the preferred solution for users who want to use upb protos in a C++
application. Unlike the upb C generated code, hpb provides a stable API and
properly handles naming conflicts. hpb is also far more ergonomic than the upb
generated code.

## Why hpb?

- As mentioned in go/upb, the upb C API is not stable, and not intended for
use in applications. hpb fills this gap.
- upbc gencode can change and break clients at any time. hpb is designed
for user applications inside of g3 and has stronger guarantees of api
stability
- LSCs/cleanups are handled by the Protobuf team - less maintenance burden
- Code will be more readable. Regular C++ method calls vs field accessors. No
need to provide fully qualified names in terra hpb.
- `my_project_MyMessage_set_x` vs `msg.set_x()`
- [planned] Gives a transition path if your team wishes to move from proto2::cpp to upb
via hpb(cpp) -> hpb(upb). All toggled statically with a BUILD flag
- [planned] interop between hpb(upb) and hpb(cpp)

## How can I get access?

hpb is currently in special availability. If you think this would be a good
fit for your team, please reach out to the Protobuf team.

8 changes: 8 additions & 0 deletions hpb/g3doc/sitemap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# hpb::

<!--*
# Document freshness: For more information, see go/fresh-source.
freshness: { owner: 'hongshin' reviewed: '2025-05-14' }
*-->

* [Home](/third_party/protobuf/hpb/g3doc/index.md)
12 changes: 12 additions & 0 deletions python/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,20 @@ static PyObject* PyUpb_FieldDescriptor_GetCppType(PyUpb_DescriptorBase* self,
return PyLong_FromLong(cpp_types[upb_FieldDef_CType(self->def)]);
}

static void WarnDeprecatedLabel(void) {
static int deprecated_label_count = 100;
if (deprecated_label_count > 0) {
--deprecated_label_count;
PyErr_WarnEx(
PyExc_DeprecationWarning,
"label() is deprecated. Use is_required() or is_repeated() instead.",
3);
}
}

static PyObject* PyUpb_FieldDescriptor_GetLabel(PyUpb_DescriptorBase* self,
void* closure) {
WarnDeprecatedLabel();
return PyLong_FromLong(upb_FieldDef_Label(self->def));
}

Expand Down
Loading
Loading