[Python-Dev] Dataclasses and correct hashability

Elvis Pranskevichus elprans at gmail.com
Thu Feb 1 20:49:44 EST 2018


On Thursday, February 1, 2018 8:37:41 PM EST Eric V. Smith wrote:
> > hash=None and compare=True leads to the same result, which, I
> > think is even worse.
> 
> Have you actually tried that?

I meant this:

@dataclasses.dataclass(hash=True)
class A:
    foo: int = dataclasses.field(compare=True)

> I don't recommend ever specifying the decorator hash= parameter
> unless you have an unusual use case, in which case it's on you to
> get it right. 

In my experience this type of breakage is so subtle that people will 
happily write code lots of code like this without noticing.  My main 
objection here is that the dataclass does not go far enough to prevent 
obviously wrong behaviour.  Or it goes too far with the whole hash/
frozen distinction.

                             Elvis




More information about the Python-Dev mailing list