rnag / rnag/dataclass-wizard

YAMLWizard skip_defaults

Open
#86 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

acknowledged awaiting-user-input documentation
Dominant language
Python
Stars
250
Forks
36
PR merge metrics
No merged PRs in 30d

Description

  • Dataclass Wizard version: 0.22.2
  • Python version: 3.10
  • Operating System: MacOS
Description

I am trying to figure out the "correct" way to use skip_defaults with the YAMLWizard mixin

What I Did

I have found two ways to get it working

  1. By subclassing YAMLWizard
class NoDefaultsWizard(YAMLWizard):

    def __init_subclass__(cls, key_transform=None):
        DumpMeta(skip_defaults=True).bind_to(cls)

@dataclass
class TestClass(NoDefaultsWizard):
    a: list[int] = field(default_factory=list)
    b: list[int] = field(default_factory=list)

c = TestClass(a=[1, 2])
print(c.to_yaml())
  1. Binding after the class definition
@dataclass
class TestClass(YAMLWizard):
    a: list[int] = field(default_factory=list)
    b: list[int] = field(default_factory=list)

DumpMeta(skip_defaults=True).bind_to(TestClass)
c = TestClass(a=[1, 2])
print(c.to_yaml())

Are either of these the recommended approach?

I looked at the options here but it seems these only work for JSONSerializable classes of which YAMLWizard is not one

If either of these are preferred, I'd be happy to submit a PR to add their usage to the docs for YAMLWizard.

Thanks for the great library!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the YAMLWizard and DumpMeta usage shown in the issue, then compare it with the linked meta options documentation. Confirm which approach is recommended for skip_defaults with YAMLWizard and document that usage; the documentation should clearly cover the supported pattern and example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.