Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omit_defaults supports specifying tuple/frozenset default values via default_factory #653

Merged
merged 1 commit into from
Mar 10, 2024

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Mar 10, 2024

Previously omit_defaults would only detect tuple/frozenset fields containing default values if the default was specified by value.

class Ex(msgspec.Struct, omit_defaults=True):
    x: tuple = ()                                    # omit_defaults would work properly with this spelling
    y: tuple = msgspec.field(default=())             # or with this spelling
    z: tuple = msgspec.field(default_factory=tuple)  # but not with this spelling

We now also support if these types are specified via default_factory (all 3 cases above now properly work with omit_defaults=True).

Note that since tuple and frozenset values are immutable there's no real reason to prefer default_factory for defaults of these types.

Fixes #652.

Previously `omit_defaults` would only detect `tuple`/`frozenset` fields
containing default values if the default was specified by value. We now
also support if these types are specified via `default_factory`.

Note that since `tuple` and `frozenset` values are immutable there's no
real reason to prefer `default_factory` for defaults of these types.
@jcrist jcrist merged commit 13a06dd into main Mar 10, 2024
8 checks passed
@jcrist jcrist deleted the omit-defaults-immutable-factories branch March 10, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

omit_defaults does not omit tuples and frozensets
1 participant