Python 3.10 TypeError when using dataclass with a default factory in nested structure
After trying multiple solutions online, I still can't figure this out. I'm encountering a `TypeError` when trying to use a nested dataclass structure in Python 3.10. I have a main dataclass `Person` that contains another dataclass `Address`. The `Address` class has a field that uses a default factory for a list. However, when I try to create a `Person` instance without providing an `Address`, I get the following error: ``` TypeError: 'field' object is not subscriptable ``` Hereβs the code Iβve written: ```python from dataclasses import dataclass, field @dataclass class Address: street: str city: str zip_code: str = field(default="00000") tags: list = field(default_factory=list) @dataclass class Person: name: str age: int address: Address = field(default_factory=Address) # Attempting to create a Person instance without an Address try: person = Person(name="John Doe", age=30) except TypeError as e: print(f'Error: {e}') ``` In this setup, I'm trying to use `Address` as a default factory for the `address` field in `Person`. However, I expected it to use the default constructor of `Address` when I don't provide one. Iβve tried changing the `default_factory` to just `None` and then checking for that in the `__post_init__` method of `Person`, but that feels cumbersome. Is there a more Pythonic way to handle this scenario? Any insights into why I'm getting this error would also be appreciated. Additionally, is it possible to have a mutable default value (like a list) in nested dataclass structures without running into common pitfalls? Thanks in advance! I recently upgraded to Python 3.9. Any pointers in the right direction?