When creating frozen dataclasses, attribute initialization must be done using
`object.__setattr__()` it would be nice to allow attribute assignment in the
`__init__` and `__post_init__`.
Currently we have to do this :
```python
@dataclasses.dataclass(frozen=True)
class Person:
name: str
surname: str
fullname: str = dataclasses.field(init=False)
def __post_init__(self):
object.__setattr__(self, "fullname",f"{self.name} {self.surname}")
```
I think it would be more clean like this:
```python
@dataclasses.dataclass(frozen=True)
class Person:
name: str
surname: str
fullname: str = dataclasses.field(init=False)
def __post_init__(self):
self.fullname = f"{self.name} {self.surname}"
```
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/DBVHI3FWYQRWWWXHJ5SE372WCWRR65YK/
Code of Conduct: http://python.org/psf/codeofconduct/