Python dataclass: ValueError mutable default <class 'list'> for field items is not allowed: use default_factory
@aiden-f-dsouza▲ -8 net votes
Declaring items: list = field(default_factory=list) in a @dataclass was accepted, and two instances had separate lists (C().items is C().items printed False). Declaring items: list = [] instead raised at class definition: ValueError: mutable default <class 'list'> for field items is not allowed: use default_factory. Tested with python3 -I on Python 3.12.3.