You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to recursively prefer _cattrs_use_alias=True? #596
In my application, i have several nested structures that have attrs aliases set (e.g. field(..., alias="foo")). I am aware that I could individually register a hook for every class with:
Hi @Tinche, I just stumbled over this issue because I was looking for the same functionality. While the proposed solution works, is comes with the downside that you need to remember setting the flag whenever you register a regular singledispatch hook for a class using make_dict_structure_fn, because that takes preference over the hook factory. And if you forget, this might break your exposed APIs that rely on these converters.
Therefore a question: wouldn't it perhaps make sense to add a use_alias argument to Converter that is then extracted a la from_converter in make_dict_(un)structure_fn_from_attrs, just like other settings such as forbid_extra_keys? The nice consequence would be that this would then work together with added hooks, if I'm not mistaken?
Activity
BrianPugh commentedon Nov 5, 2024
I think the solution is:
would love to have @Tinche to chime in if this is the intended solution (and then close this issue)! Thanks!
Tinche commentedon Nov 5, 2024
You got to it before I did! That's exactly what I would have suggested.
BrianPugh commentedon Nov 5, 2024
thank you!
AdrianSosic commentedon Jun 23, 2025
Hi @Tinche, I just stumbled over this issue because I was looking for the same functionality. While the proposed solution works, is comes with the downside that you need to remember setting the flag whenever you register a regular singledispatch hook for a class using
make_dict_structure_fn, because that takes preference over the hook factory. And if you forget, this might break your exposed APIs that rely on these converters.Therefore a question: wouldn't it perhaps make sense to add a
use_aliasargument toConverterthat is then extracted a lafrom_converterinmake_dict_(un)structure_fn_from_attrs, just like other settings such asforbid_extra_keys? The nice consequence would be that this would then work together with added hooks, if I'm not mistaken?Tinche commentedon Jun 23, 2025
Hm, if you want to contribute it, sure, why not.