I have a dataclass with a mutable field (a list). What I'm hoping to achieve is that this field will never be None, even when explicitly set to None in the __init__ call. In a normal class this would be trivial to implement:
class A:
def __init__(self, l: Optional[List[int]] = None):
if l is None:
l = []
self.l = l
Is there a way to achieve the same result with just the dataclasses.field function, i.e. without explicitly implementing an __init__ method (which would be cumbersome when the class has a lot of attributes)? Can I force dataclasses.field to call its default_factory
when the supplied init argument is None?