Skip to content

Commit 4d1154e

Browse files
authoredSep 20, 2022
Fix cattr in Python 3.9 (#967)
* Remove structuring hook for forward reference and handle manually * Handle missing key
1 parent be89412 commit 4d1154e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎sleap/instance.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,13 @@ def structure_instances_list(x, type):
12321232
if "score" in inst_data.keys():
12331233
inst = converter.structure(inst_data, PredictedInstance)
12341234
else:
1235+
if (
1236+
"from_predicted" in inst_data
1237+
and inst_data["from_predicted"] is not None
1238+
):
1239+
inst_data["from_predicted"] = converter.structure(
1240+
inst_data["from_predicted"], PredictedInstance
1241+
)
12351242
inst = converter.structure(inst_data, Instance)
12361243
inst_list.append(inst)
12371244

@@ -1243,14 +1250,13 @@ def structure_instances_list(x, type):
12431250

12441251
# Structure forward reference for PredictedInstance for the Instance.from_predicted
12451252
# attribute.
1246-
converter.register_structure_hook(
1247-
ForwardRef("PredictedInstance"),
1248-
lambda x, _: converter.structure(x, PredictedInstance),
1253+
converter.register_structure_hook_func(
1254+
lambda t: t.__class__ is ForwardRef,
1255+
lambda v, t: converter.structure(v, t.__forward_value__),
12491256
)
1250-
12511257
# converter.register_structure_hook(
1252-
# PredictedInstance,
1253-
# lambda x, type: converter.structure(x, PredictedInstance),
1258+
# ForwardRef("PredictedInstance"),
1259+
# lambda x, _: converter.structure(x, PredictedInstance),
12541260
# )
12551261

12561262
# We can register structure hooks for point arrays that do nothing

0 commit comments

Comments
 (0)
Please sign in to comment.