This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients eric.smith, rhettinger
Date 2018-12-18.21:13:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545167633.41.0.788709270274.issue35527@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2018-12-18 21:13:53rhettingersetrecipients: + rhettinger, eric.smith
2018-12-18 21:13:53rhettingersetmessageid: <1545167633.41.0.788709270274.issue35527@psf.upfronthosting.co.za>
2018-12-18 21:13:53rhettingerlinkissue35527 messages
2018-12-18 21:13:53rhettingercreate