cattrs
cattrs copied to clipboard
omit_if_default ignores attrs' converters
Hi! It seems like currently converter with omit_if_default=True does not apply attrs' converters when checking if the value is equal to the default one.
import attrs
import cattrs
c = cattrs.Converter(omit_if_default=True)
@attrs.define
class A:
b: int = attrs.field(default="0", converter=int)
c.unstructure(A())
# {'b': 0}
@attrs.define
class A:
b: int = attrs.field(default=0, converter=int)
c.unstructure(A())
# {}
Is this the expected behavior? If so, would you consider changing it?
I hadn't really considered this. I'd be open to changing it.
I hadn't really considered this. I'd be open to changing it.
Glad that you're open to changing it! I think i've managed to make it work, here's a pull request with my changes
https://github.com/python-attrs/cattrs/pull/696