defaultfactory
Defaultfactory, often written as default_factory, is a programming concept describing a callable used to generate default values for missing entries in a data structure. The callable is invoked without arguments to supply a value when a requested key or field does not yet exist. This pattern helps avoid repeated checks for presence and ensures consistent, initialized defaults.
In Python, the term is most commonly encountered in two contexts. The collections.defaultdict class has an attribute
The second major use is in dataclasses, where the field function accepts a default_factory keyword argument.
Key characteristics: default_factory must be a zero-argument callable; it is invoked only when a new default
Historically, default factories in Python originated with the collections module (defaultdict) and later expanded to dataclasses