Python 3.10 TypeError when using dataclasses with default factory and immutable fields
I've encountered a strange issue with I'm running into an scenario when trying to use Python's `dataclasses` module with immutable fields and a default factory. I have a use case where I want a field in my data class to have a default value generated by a function, but it must also be immutable after being set. Here's a simplified version of my code: ```python from dataclasses import dataclass, field import random @dataclass(frozen=True) class User: id: int = field(default_factory=random.randint(1, 100)) name: str user = User(name='Alice') print(user) ``` When I run this code, I get the following behavior: ``` TypeError: want to assign to field 'id' ``` I expected the `id` to be assigned a random integer between 1 and 100 when creating a new `User` instance. However, since `User` is marked as `frozen`, it appears that the `default_factory` doesn't behave as I expected. I've tried different variations, including removing `frozen=True`, but that doesn't suit my use case as I need the immutability. I've also looked into using a `__post_init__` method to set the `id`, but that seems counterintuitive for a data class design. Is there a way to achieve what I'm trying to do without losing the benefits of immutability? Should I reconsider how I'm structuring my data class, or is there a way to work around this scenario? Any insights or alternative approaches would be greatly appreciated! Has anyone else encountered this? Thanks in advance!