Closed ares-b closed 1 year ago
Cattrs cannot structure My Class if one of my attributes type is a Parent Type of other Child types.
import attrs import cattrs @attrs.define class A: pass @attrs.define class B(A): z: float = attrs.field(validator=attrs.validators.instance_of(float)) @attrs.define class MyClass: test: A = attrs.field(validator=attrs.validators.instance_of(A)) mbis = cattrs.structure({"test": {"z": 3.0}}, MyClass) # mbis = MyClass(test=A()) # should be MyClass(test=B(z=3.0))
You might want to keep an eye on https://github.com/python-attrs/cattrs/pull/312, I think that's what you're after.
Description
Cattrs cannot structure My Class if one of my attributes type is a Parent Type of other Child types.
What I Did