On 2 February 2018 at 15:38, Elvis Pranskevichus <elpr...@gmail.com> wrote: > On Friday, February 2, 2018 10:08:43 AM EST Eric V. Smith wrote: >> However, I don't feel very strongly about this. As I've said, I expect >> the use cases for hash=True to be very, very rare. > > Why do you think that the requirement to make a dataclass hashable is a > "very, very rare" requirement? The moment you want to use a dataclass a > a dict key, or put it in a set, you need it to be hashable. > > Just put yourself in the shoes of an average Python developer. You try > to put a dataclass in a set, you get a TypeError. Your immediate > reaction is to add "hash=True". Things appear to work. Then, you, or > someone else, decides to mutate the dataclass object and then you are > looking at a very frustrating debug session.
If I saw someone try to put a dataclass into a set, I'd point out that dataclasses are *mutable*, and if they want immutable values they should use "frozen=True". If it were me in that situation, that's what I'd do as well. Adding hashability to a mutable object would *never* be my immediate reaction. To put it another way, using your words above, "The moment you want to use a dataclass a a dict key, or put it in a set, you need it to be *immutable*" (not hashable, unless you really know what you're doing). Paul _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com