Message332080
The unsafe_hash option is unsafe only because it doesn't afford mutability protections. This can be mitigated with selective immutability.
@dataclass
class Person:
ssn: int = field(immutable=True)
birth_city: int = field(immutable=True)
name: str # A person can change their name
address: str # A person can move
age: int # An age can change
This would generate something like this:
def __setattr__(self, attr, value):
if attr in {'ssn', 'birth_city'} and hasattr(self, attr):
raise TypeError(
f'{attr!r} is not settable after initialization')
return object.__setattr__(self, name, attr)
A number of APIs are possible -- the important thing to be able to selectively block updates to particular fields (particularly those used in hashing and ordering). |
|
Date |
User |
Action |
Args |
2018-12-18 21:13:53 | rhettinger | set | recipients:
+ rhettinger, eric.smith |
2018-12-18 21:13:53 | rhettinger | set | messageid: <1545167633.41.0.788709270274.issue35527@psf.upfronthosting.co.za> |
2018-12-18 21:13:53 | rhettinger | link | issue35527 messages |
2018-12-18 21:13:53 | rhettinger | create | |
|