@@ -779,7 +779,7 @@ def __bytes__(self) -> bytes:
779779 # Default (zero) values are not serialized.
780780 continue
781781
782- if isinstance ( value , list ) :
782+ if meta . repeated :
783783 if meta .proto_type in PACKED_TYPES :
784784 # Packed lists look like a length-delimited field. First,
785785 # preprocess/encode each value into a buffer and then
@@ -802,9 +802,8 @@ def __bytes__(self) -> bytes:
802802 or b"\n \x00 "
803803 )
804804
805- elif isinstance ( value , dict ) :
805+ elif meta . map_meta :
806806 for k , v in value .items ():
807- assert meta .map_meta
808807 sk = _serialize_single (1 , meta .map_meta [0 ].proto_type , k )
809808 sv = _serialize_single (2 , meta .map_meta [1 ].proto_type , v , unwrap = meta .map_meta [1 ].unwrap )
810809 stream .write (_serialize_single (meta .number , meta .proto_type , sk + sv ))
@@ -944,8 +943,10 @@ def load(
944943
945944 meta = proto_meta .meta_by_field_name [field_name ]
946945
946+ is_packed_repeated = parsed .wire_type == WIRE_LEN_DELIM and meta .proto_type in PACKED_TYPES
947+
947948 value : Any
948- if parsed . wire_type == WIRE_LEN_DELIM and meta . proto_type in PACKED_TYPES :
949+ if is_packed_repeated :
949950 # This is a packed repeated field.
950951 pos = 0
951952 value = []
@@ -969,8 +970,8 @@ def load(
969970 if meta .proto_type == TYPE_MAP :
970971 # Value represents a single key/value pair entry in the map.
971972 current [value .key ] = value .value
972- elif isinstance ( current , list ) :
973- if isinstance ( value , list ) :
973+ elif meta . repeated :
974+ if is_packed_repeated :
974975 current .extend (value )
975976 else :
976977 current .append (value )
@@ -1142,7 +1143,12 @@ def _from_dict_init(cls, mapping: Mapping[str, Any] | Any, *, ignore_unknown_fie
11421143 raise KeyError (f"Unknown field '{ field_name } ' in message { cls .__name__ } ." ) from None
11431144
11441145 if value is None :
1145- continue
1146+ name , module = field_cls .__name__ , field_cls .__module__
1147+
1148+ # Edge case: None shouldn't be ignored for google.protobuf.Value
1149+ # See https://protobuf.dev/programming-guides/json/
1150+ if not (module .endswith ("google.protobuf" ) and name == "Value" ):
1151+ continue
11461152
11471153 if meta .proto_type == TYPE_MESSAGE :
11481154 if meta .repeated :
0 commit comments