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
Basically, I would like to have all the fields except notes be frozen. Additionally, I don't want notes to be taken into account for __hash__ and __eq__ (or the ordering methods, if order is True), and I expect it should be excluded from the pattern-matching support (__match_args__) too. The non-frozen field should still be encoded/decoded, but it doesn't matter in terms of the "value" of the struct.
(Of course, I can use my recipe here, but I would also have to implement my own __hash__ and __eq__ methods, which I'm not looking forward to.)
I know msgspec.structs.force_setattr exists, but I'm not 100% clear on when it is more or less safe to use it. However I do know that using it alters the hash for the struct, which doesn't work with what I want here.
If I had to design an API for this, I think would have a keep_thawed keyword argument in msgspec.field, with a doc note that it does nothing unless the struct is frozen, and if frozen, it excludes that field from the various value-related dunder methods.
Description
I've been converting attrs-based classes to structs in one of my projects, and I have a use case for a partially-frozen struct.
Basically, I would like to have all the fields except
notes
be frozen. Additionally, I don't wantnotes
to be taken into account for__hash__
and__eq__
(or the ordering methods, iforder
is True), and I expect it should be excluded from the pattern-matching support (__match_args__
) too. The non-frozen field should still be encoded/decoded, but it doesn't matter in terms of the "value" of the struct.(Of course, I can use my recipe here, but I would also have to implement my own
__hash__
and__eq__
methods, which I'm not looking forward to.)I know
msgspec.structs.force_setattr
exists, but I'm not 100% clear on when it is more or less safe to use it. However I do know that using it alters the hash for the struct, which doesn't work with what I want here.If I had to design an API for this, I think would have a
keep_thawed
keyword argument inmsgspec.field
, with a doc note that it does nothing unless the struct is frozen, and if frozen, it excludes that field from the various value-related dunder methods.The text was updated successfully, but these errors were encountered: