YAMLWizard skip_defaults
Nobody has claimed this yet.
- 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
- 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())
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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