Open MicaelJarniac opened 2 years ago
Sort of related, but not quite: https://github.com/python-attrs/attrs/issues/391
So when you pass omit_if_default=True
to the GenConverter, it'll use it when it calls make_dict_unstructure_fn
for you. But if you're calling it yourself, you need to pass it in yourself too. So do:
unstruct_hook = cattr.gen.make_dict_unstructure_fn(
Whatever,
c,
u_thing=cattr.override(rename="_thing"), _cattrs_omit_if_default=True
)
c.register_unstructure_hook(Whatever, unstruct_hook)
The parameter name is a little mangled to not clash with a possible attribute of that name.
We could make it so that the converter behavior is used if the flag is not set explicitly. If you feel like putting together a PR for this, I'd be happy to merge it in ;)
Description
I'm yet to get a minimal working example, but it's something like so:
I do a lot of other things to the converters, but from my testing, this is what's breaking it.
I need those extra hooks because I need both
thing
and_thing
to show up on the output, and attrs doesn't seem to allow that, so I need to rename it on the fly.