[Python-Dev] unfrozen dataclasses and __hash__ (subsets are OK)
Jim J. Jewett
jimjjewett at gmail.com
Sun Feb 4 23:42:01 EST 2018
More information about the Python-Dev mailing list
Sun Feb 4 23:42:01 EST 2018
- Previous message (by thread): [Python-Dev] [RELEASED] Python 3.4.8 and Python 3.5.5 are now available
- Next message (by thread): [Python-Dev] [RELEASE] Python 3.7.0b1 is now available for testing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I understand auto-generating the __hash__ (and __eq__) for a frozen container; that is just convenient. But why is there any desire to autogenerate a __hash__ for something that isn't frozen? Like a list or dict, the normal case would be for it not to have a hash at all, and the author *should* write out any explicit exceptions. The objection to that seems to be that someone might forget to add another field to the hash during later maintenance -- but so what? __hash__ should reference a subset of the fields used for equality, and strict subsets are OK. It *should* ignore some fields if that will provide the right balance between quick calculation and sufficient dispersion. If the record is complicated enough that forgetting a field is a likely problem, then the hash is probably already sufficiently complex without those new fields. -jJ
- Previous message (by thread): [Python-Dev] [RELEASED] Python 3.4.8 and Python 3.5.5 are now available
- Next message (by thread): [Python-Dev] [RELEASE] Python 3.7.0b1 is now available for testing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list