keying by identity in dict and set

Chris Angelico rosuav at gmail.com
Sun Oct 20 14:35:17 EDT 2019


On Mon, Oct 21, 2019 at 4:33 AM Steve White <stevan.white at gmail.com> 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.

ChrisA



More information about the Python-list mailing list