Currently, default values can't be mutable (e.g. []), because they're instantiated when the class is being setup, and are therefore shared between all instances of a class.
Some solutions:
Make a copy of the default for each object:
Pros:
Mutable objects would work transparently.
Cons:
Non-copyable object could not be used as defaults.
Experienced devs might be surprised by this.
Provide a way to specify a callable:
Pros:
Would support everything.
This is how other similar libraries seem to approach this, e.g. dataclass, attrs
Cons:
default itself could be a callable, so we would need a new attribute.
Currently, default values can't be mutable (e.g.
[]
), because they're instantiated when the class is being setup, and are therefore shared between all instances of a class.Some solutions:
Make a copy of the default for each object:
Provide a way to specify a callable:
dataclass
,attrs
default
itself could be a callable, so we would need a new attribute.