[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keying by identity in dict and set

On Mon, Oct 21, 2019 at 4:33 AM Steve White <stevan.white at> wrote:
> The options for following the documentation in this situation are:
> either subject users to unfamiliar, custom-made container classes, or
> give up the semantics of the "==" operator.
> It seems so unnecessary, given (my understanding of) how the classes
> actually function.
> What can be done?  I would be willing to consider a technical solution.
> I would like to see the documentation revised to reflect the actual
> workings of the existing container classes.  A couple of sentences in
> the documentation of __hash__ could fix the problem.

The definition of __hash__ is still correct. What you're looking at is
a very specific situation wherein an object is not equal to itself -
that's incredibly rare (in the core language, the ONLY thing that can
ever be like this is a NaN). The dictionary's rule is that it finds
any object that is either identical to, or equal to, the thing you
asked for.