Skip to content

Commit 3894d49

Browse files
committed
Correctly parse List[X] annotated objects from dictionaries
1 parent ab01bec commit 3894d49

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pycardano/plutus.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,25 @@ def _dfs(obj):
589589
raise DeserializeException(
590590
f"Unexpected data structure: {f}."
591591
)
592+
elif (
593+
hasattr(f_info.type, "__origin__")
594+
and f_info.type.__origin__ is list
595+
):
596+
t_args = f_info.type.__args__
597+
if len(t_args) != 1:
598+
raise DeserializeException(
599+
f"List types need exactly one type argument, but got {t_args}"
600+
)
601+
if "list" not in f:
602+
raise DeserializeException(f"Expected type \"list\" for constructor List but got {f}")
603+
t = t_args[0]
604+
if (
605+
inspect.isclass(t)
606+
and issubclass(t, PlutusData)
607+
):
608+
converted_fields.append(t.from_dict(f))
609+
else:
610+
converted_fields.append(_dfs(f))
592611
else:
593612
converted_fields.append(_dfs(f))
594613
return cls(*converted_fields)

0 commit comments

Comments
 (0)