Message332847
Hi @rhettinger, this is similar to #33474.
I started working on an implementation of this.
With the implementation you propose, if a field has both init=True and frozen=True, it may be set after the creation of the instance:
@dataclass
class Person:
ssn: int = field(init=False, frozen=True)
name: str
p = Person(name='foo')
p.name = 'bar'
p.ssn = 1234
Wouldn't this conflict with the purpose of safe hashing?
I think it would need __setattr__ to be:
def __setattr__(self, attr, value):
if attr in {'ssn', 'birth_city'}:
raise TypeError(
f'{attr!r} is not settable after initialization')
return super(cls, self).__setattr__(self, name, attr)
wouldn't it? |
|
Date |
User |
Action |
Args |
2019-01-02 00:12:55 | remi.lapeyre | set | recipients:
+ remi.lapeyre, rhettinger, eric.smith, yselivanov |
2019-01-02 00:12:54 | remi.lapeyre | set | messageid: <1546387974.33.0.310266178925.issue35527@roundup.psfhosted.org> |
2019-01-02 00:12:54 | remi.lapeyre | link | issue35527 messages |
2019-01-02 00:12:54 | remi.lapeyre | create | |
|