Siyet · GitHub

Copy link Copy Markdown

Contributor

omit_defaults only recognizes empty-collection defaults when the default is given by value or via a builtin collection constructor (list/dict/set/tuple/frozenset). A custom default_factory (a user function, lambda, or a Struct/dataclass/attrs type) is never called during detection, so its field is always encoded, even when the produced value is empty.

This is intentional: detection runs in the encode hot path and stays O(1) without invoking user code. The behavior wasn't documented though, so the matches_default section now spells out the default_factory limitation and points at default_factory=list (which type checks fine via the field annotation) as the supported way to omit an empty collection default.

Closes #1032
Closes #645

Read the original on github.com ↗