On Tue, Nov 16, 2021 at 7:17 PM Paul Bryan <pbr...@anode.ca> wrote: > On Tue, 2021-11-16 at 17:04 +0400, Abdur-Rahmaan Janhangeer wrote: > > A simple question: why do we need field(default_factory ) in dataclasses? > > > To initialize a default value when a new instance of the dataclass is > created. For example, if you want a field to default to a dict. A new dict > is created for each instance of the dataclass created. >
Why not have an attribute which returns a deep copy of a dict? Like the only advantage of default factory is copying whatever we specify? -- https://mail.python.org/mailman/listinfo/python-list