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
Hi cattrs team,
I encountered a seemingly quite surprising feature of cattrs, namely that the ordering of registered hooks could affect the serialization outcome of nested attrs or dataclasses.
See the two cases below.
I guess it would be not too surprising if one understands that make_dict_unstructure_fn relies on context information (what has been registered and what is in namespace, perhaps).
But I think this could be confusing behavior, and more information could be added to the documentation. Or perhaps, some different mechanism should be implemented to make the ordering does not matter.
Whether the order of hook registration matters or not is technically dependent on which hooks you use, but the vast majority of default hooks uses early hook resolution, so in practice the order always matters.
Hi cattrs team,
I encountered a seemingly quite surprising feature of cattrs, namely that the ordering of registered hooks could affect the serialization outcome of nested attrs or dataclasses.
See the two cases below.
I guess it would be not too surprising if one understands that
make_dict_unstructure_fn
relies on context information (what has been registered and what is in namespace, perhaps).But I think this could be confusing behavior, and more information could be added to the documentation. Or perhaps, some different mechanism should be implemented to make the ordering does not matter.
cattrs version: 24.1.2
python version: 3.9.6
If the order of hooks is reversed
The text was updated successfully, but these errors were encountered: