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
omit_defaults does not omit tuples and frozensets #652
When a struct has omit_defaults=True set, any fields defaulting to dict, list, or set is omitted from the serialization, as described in the docs.
However, if one is using tuple instead of list and frozenset instead of set as default values, to make the struct as immutable as possible, those defaults are included in the encoded format.
I think that tuple and frozenset should be handled in the same way as dict, list, and setbyomit_defaultsandrepr_omit_defaults`.
Thanks for opening this - this should be fixed by #653. Note that for these cases specifying the default value by value (rather than via default_factory) already works:
The reason tuple and frozenset are the special cases here is that they're both immutable types and may always be specified by value. Since there's no functional reason to use a default_factory for these types, we hadn't implemented the logic to check for equivalent defaults based on default_factory for tuple/frozenset.
Activity
jcrist commentedon Mar 10, 2024
Thanks for opening this - this should be fixed by #653. Note that for these cases specifying the default value by value (rather than via
default_factory) already works:The reason
tupleandfrozensetare the special cases here is that they're both immutable types and may always be specified by value. Since there's no functional reason to use adefault_factoryfor these types, we hadn't implemented the logic to check for equivalent defaults based ondefault_factoryfortuple/frozenset.jodal commentedon Mar 10, 2024
Thank you for the very swift fix! Especially useful with the tip on how to achieve this without waiting for a new release :-)
models: Remove empty collections from repr/serialization
models: Remove empty collections from repr/serialization
models: Remove empty collections from repr/serialization
models: Remove empty collections from repr/serialization
models: Remove empty collections from repr/serialization