Skip to content

Commit 5aa8213

Browse files
committed
Fix parsing List[x] from cbor
1 parent 39331f8 commit 5aa8213

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pycardano/serialization.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ def _restore_dataclass_field(
413413
return f.metadata["object_hook"](v)
414414
elif isclass(f.type) and issubclass(f.type, CBORSerializable):
415415
return f.type.from_primitive(v)
416+
elif hasattr(f.type, "__origin__") and (f.type.__origin__ is list):
417+
t_args = f.type.__args__
418+
if len(t_args) != 1:
419+
raise DeserializeException(
420+
f"List types need exactly one type argument, but got {t_args}"
421+
)
422+
t = t_args[0]
423+
if isclass(t) and issubclass(t, CBORSerializable):
424+
return IndefiniteList([t.from_primitive(w) for w in v])
425+
else:
426+
return IndefiniteList(v)
416427
elif isclass(f.type) and issubclass(f.type, IndefiniteList):
417428
return IndefiniteList(v)
418429
elif hasattr(f.type, "__origin__") and (

test/pycardano/test_plutus.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ def test_plutus_data():
7979
check_two_way_cbor(my_vesting)
8080

8181

82-
@unittest.skip(
83-
"From CBOR is generally not correctly implemented for tags > 7, so this test fails"
84-
)
8582
def test_plutus_data_list_cbor():
8683
test = ListTest([LargestTest(), LargestTest()])
8784

0 commit comments

Comments
 (0)