Can anyone help me fix this error. I just started using dataclass I wanted to put a default value so I can easily call from other function
I have this class
@dataclass(frozen=True)
class MyClass:
my_list: list = ["list1", "list2", "list3"]
my_list2: list = ["list1", "list2", "list3"]
But when i print print(MyClass.my_list) I'm getting this error
raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'list'> for field my_list is not allowed: use default_factory
frozen=Truewon't change the error, but all I meant is that as a general concept, a 'frozen' object with mutable contents is somewhat contradictory. There can be complications with hashing (see the documentation) so it may be better to avoid frozen in this case if you don't need it.