Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive type with List[] causing RecursionError #136

Closed
gkaemmer opened this issue Oct 29, 2020 · 0 comments · Fixed by #137
Closed

Recursive type with List[] causing RecursionError #136

gkaemmer opened this issue Oct 29, 2020 · 0 comments · Fixed by #137
Assignees
Labels
bug Something isn't working

Comments

@gkaemmer
Copy link

gkaemmer commented Oct 29, 2020

  • typical version: 2.0.25 2.0.32
  • Python version: 3.8.1
  • Operating System: Mac OSX

Description

Trying to use typical to serialize/deserialize a type that has a recursive field of type List:

@dataclasses.dataclass
class Node:
    children: List["Node"]

typic.transmute(Node, {"children": []})
# => raises RecursionError: maximum recursion depth exceeded

What I Did

Tried using "List[Node]" as the type, and 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:

@dataclasses.dataclass
class Node:
    child: Optional["Node"]

typic.transmute(Node, {"children": Node})
# => Node(child=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants