File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66from typing import Any
77
88from google .protobuf import struct_pb2
9- from google .protobuf .json_format import ParseDict
9+ from google .protobuf .json_format import MessageToDict , ParseDict
1010
1111from a2a .types .a2a_pb2 import (
1212 Artifact ,
@@ -404,16 +404,16 @@ def get_text_parts(parts: Sequence[Part]) -> list[str]:
404404def get_data_parts (parts : Sequence [Part ]) -> list [Any ]:
405405 """Extracts structured data from all data Parts.
406406
407- Each returned element is the Python object obtained from the
408- ``google.protobuf.Value`` stored in the Part .
407+ Each returned element is the Python object obtained by converting
408+ the ``google.protobuf.Value`` back via ``MessageToDict`` .
409409
410410 Args:
411411 parts: A sequence of ``Part`` objects.
412412
413413 Returns:
414- A list of deserialized data values from any data Parts found.
414+ A list of deserialized Python objects from any data Parts found.
415415 """
416- return [part .data for part in parts if part .HasField ('data' )]
416+ return [MessageToDict ( part .data ) for part in parts if part .HasField ('data' )]
417417
418418
419419def get_raw_parts (parts : Sequence [Part ]) -> list [bytes ]:
Original file line number Diff line number Diff line change 22
33import pytest
44
5- from a2a .helpers . proto_helpers import (
5+ from a2a .helpers import (
66 get_artifact_text ,
77 get_data_parts ,
88 get_message_text ,
@@ -462,8 +462,8 @@ def test_get_data_parts() -> None:
462462 ]
463463 result = get_data_parts (parts )
464464 assert len (result ) == 2
465- assert result [0 ]. struct_value . fields [ 'key' ]. string_value == ' value'
466- assert result [1 ]. list_value . values [ 0 ]. number_value == 1
465+ assert result [0 ] == { 'key' : ' value'}
466+ assert result [1 ] == [ 1 , 2 ]
467467
468468
469469def test_get_data_parts_empty () -> None :
You can’t perform that action at this time.
0 commit comments