Skip to content

Commit d89f04a

Browse files
fix: replace deprecated FieldDescriptor.label with is_repeated
Replace all three uses of `field.label == FieldDescriptor.LABEL_REPEATED` with `field.is_repeated` in proto_utils.py, as tracked in #1011. The `FieldDescriptor.label` property was deprecated in protobuf 4.x. Since the minimum protobuf requirement is already >=5.29.5 (where `is_repeated` is available), this cleanup is safe to apply now. Affected functions: - `parse_params()` — REST query parameter parsing - `_check_required_field_violation()` — required field validation - `_recurse_validation()` — nested message recursion Closes #1011
1 parent c0c6c08 commit d89f04a

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

src/a2a/utils/proto_utils.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ def parse_params(params: QueryParams, message: ProtobufMessage) -> None:
174174
field = fields[k]
175175
v_list = params.getlist(k)
176176

177-
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
178-
# deprecated `field.label` with `field.is_repeated` once the minimum
179-
# protobuf version requirement is bumped.
180-
if field.label == FieldDescriptor.LABEL_REPEATED:
177+
if field.is_repeated:
181178
accumulated: list[Any] = []
182179
for v in v_list:
183180
if not v:
@@ -211,10 +208,7 @@ def _check_required_field_violation(
211208
) -> ValidationDetail | None:
212209
"""Check if a required field is missing or invalid."""
213210
val = getattr(msg, field.name)
214-
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
215-
# deprecated `field.label` with `field.is_repeated` once the minimum
216-
# protobuf version requirement is bumped.
217-
if field.label == FieldDescriptor.LABEL_REPEATED:
211+
if field.is_repeated:
218212
if not val:
219213
return ValidationDetail(
220214
field=field.name,
@@ -255,10 +249,7 @@ def _recurse_validation(
255249
return errors
256250

257251
val = getattr(msg, field.name)
258-
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
259-
# deprecated `field.label` with `field.is_repeated` once the minimum
260-
# protobuf version requirement is bumped.
261-
if field.label != FieldDescriptor.LABEL_REPEATED:
252+
if not field.is_repeated:
262253
if msg.HasField(field.name):
263254
sub_errs = _validate_proto_required_fields_internal(val)
264255
_append_nested_errors(errors, field.name, sub_errs)

0 commit comments

Comments
 (0)