- cattrs version: current master (a10ad1c)
- Python version: 3.10
- Operating System: Linux
Description
I'm serializing a dataclass with a field. If the field has a more generic type than the actual instance, all the information from the child class is lost when unstructuring.
What I Did
from dataclasses import dataclass
import cattr
@dataclass(kw_only=True, frozen=True)
class Bar:
x: int
@dataclass(kw_only=True, frozen=True)
class Foo(Bar):
y: int
@dataclass(kw_only=True, frozen=True)
class Baz:
foo: Bar
converter = cattr.Converter()
foo = Baz(foo=Foo(x=1, y=2))
print("unstructured", converter.unstructure(foo))
Expectation vs Reality
I'd expect it to output unstructured {'foo': {'x': 1, 'y': 2}} but it outputs unstructured {'foo': {'x': 1}}
Is this expected behaviour due to the way Converter generates unstructuring functions? If so, how can you change that behaviour?
Description
I'm serializing a dataclass with a field. If the field has a more generic type than the actual instance, all the information from the child class is lost when unstructuring.
What I Did
Expectation vs Reality
I'd expect it to output
unstructured {'foo': {'x': 1, 'y': 2}}but it outputsunstructured {'foo': {'x': 1}}Is this expected behaviour due to the way Converter generates unstructuring functions? If so, how can you change that behaviour?