Closed gkaemmer closed 3 years ago
Trying to use typical to serialize/deserialize a type that has a recursive field of type List:
List
@dataclasses.dataclass class Node: children: List["Node"] typic.transmute(Node, {"children": []}) # => raises RecursionError: maximum recursion depth exceeded
Tried using "List[Node]" as the type, and from __future__ import annotations:
"List[Node]"
from __future__ import annotations
@dataclasses.dataclass class Node: children: "List[Node]" typic.transmute(Node, {"children": []}) # => raises RecursionError: maximum recursion depth exceeded from __future__ import annotations @dataclasses.dataclass class Node: children: List[Node] typic.transmute(Node, {"children": []}) # => raises RecursionError: maximum recursion depth exceeded
With Optional instead of List, it seems to work:
Optional
@dataclasses.dataclass class Node: child: Optional["Node"] typic.transmute(Node, {"children": Node}) # => Node(child=None)
Description
Trying to use typical to serialize/deserialize a type that has a recursive field of type
List
:What I Did
Tried using
"List[Node]"
as the type, andfrom __future__ import annotations
:With
Optional
instead ofList
, it seems to work: