adaptix
adaptix copied to clipboard
forward refs
closes #63 closes #24
refs must be set for each dataclass! (class "A" can be in several modules, and refs are set as stings with short name)
Related problem with get_type_hints. We need workaround for this code
from __future__ import annotations
from dataclasses import dataclass
from dataclass_factory import Factory
def main():
@dataclass
class ContainsInt:
x: int
@dataclass
class Data:
contents: ContainsInt
factory = Factory()
parsed = factory.load({"contents": {"x": 1}}, Data)
assert parsed == Data(ContainsInt(x=1))
if __name__ == '__main__':
main()