I'm attempting to build a simple data-class example for YAML parsing which consists of recursive types.
The YAML in question looks like this:
---
folders:
- name: a
children:
- name: b
- name: c
children: []
The way I am defining my types is like so:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations # I'm on Python 3.9
from dataclass_wizard import YAMLWizard, LoadMeta
from dataclasses import dataclass
@dataclass
class DemoManifest(YAMLWizard):
folders: List[DemoFolder]
@dataclass
class DemoFolder(YAMLWizard):
name: str
children: List[DemoFolder]
def main():
LoadMeta(recursive=True).bind_to(DemoFolder)
manifest = DemoManifest.from_yaml_file("recurse.yml")
print(manifest)
It's a pretty simple example. I have one outer type which defines a list of DemoFolder
objects, which potentially have a list of children of DemoFolder
types as well.
When I run this, I get a RecursionError
, maximum depth exceeded
. Clearly somehow recursion is breaking the parsing. I thought that I solved the issue using the meta above, but it is definitely not working.
Is it possible to do self-referential deserialization in YAML for dataclass-wizard
?
EDIT: This is not an issue of Python compiling. The code compiles and runs, it seems to be an issue with dataclass-wizard
, which is where the recursion occurs.