[Python-Dev] PEP 557: Data Classes

Eric V. Smith eric at trueblade.com
Wed Sep 13 04:44:23 EDT 2017

On 9/10/2017 11:08 PM, Nathaniel Smith wrote:
> Hi Eric,
> A few quick comments:
> Why do you even have a hash= argument on individual fields? For the 
> whole class, I can imagine you might want to explicitly mark a whole 
> class as unhashable, but it seems like the only thing you can do with 
> the field-level hash= argument is to create a class where the __hash__ 
> and __eq__ take different fields into account, and why would you ever 
> want that?

See the discussion at 
https://github.com/ericvsmith/dataclasses/issues/44 for why we're 
keeping the field-level hash function.

Quick version, from Guido: "There's a legitimate reason for having a 
field in the eq but not in the hash. After all hash is always followed 
by an eq check and it is totally legit for the eq check to say two 
objects are not equal even though their hashes are equal."

This would be in the case where a field should be used for equality 
testing, but computing its hash is expensive.


More information about the Python-Dev mailing list