Skip to content

Commit 8d9daf1

Browse files
committed
Freeze indefinite lists and definite lists when decoding
1 parent 26b4d86 commit 8d9daf1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pycardano/serialization.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ def decode_array(self, subtype: int) -> Sequence[Any]:
199199
length = self._decode_length(subtype, allow_indefinite=True)
200200

201201
if length is None:
202-
return IndefiniteList(cast(Primitive, self.decode_array(subtype=subtype)))
202+
ret = IndefiniteFrozenList(cast(Primitive, self.decode_array(subtype=subtype)))
203+
ret.freeze()
204+
return ret
203205
else:
204206
return self.decode_array(subtype=subtype)
205207

@@ -1187,12 +1189,17 @@ def __repr__(self) -> str:
11871189
return f"{self.__class__.__name__}({list(self)})"
11881190

11891191
def to_shallow_primitive(self) -> Union[CBORTag, Union[List[T], IndefiniteList]]:
1192+
if self._is_indefinite_list:
1193+
fields = IndefiniteFrozenList(list(self))
1194+
else:
1195+
fields = FrozenList(self)
1196+
fields.freeze()
11901197
if self._use_tag:
11911198
return CBORTag(
11921199
258,
1193-
IndefiniteList(list(self)) if self._is_indefinite_list else list(self),
1200+
fields,
11941201
)
1195-
return IndefiniteList(list(self)) if self._is_indefinite_list else list(self)
1202+
return fields
11961203

11971204
@classmethod
11981205
def from_primitive(

0 commit comments

Comments
 (0)