[Python-Dev] About [].append == [].append

Nathaniel Smith njs at pobox.com
Thu Jun 21 17:59:19 EDT 2018


On Thu, Jun 21, 2018 at 2:04 PM, Ivan Pozdeev via Python-Dev
<python-dev at python.org> wrote:
> On 21.06.2018 23:40, Guido van Rossum wrote:
>
> > I'm with Serhiy here, for mutable values I don't think the methods should
> > compare equal, even when the values do. For immutables I don't care either
> > way, it's an implementation detail.
>
> In this light, methods rather shouldn't have a rich comparison logic at all
> -- at the very least, until we have a realistic use case and can flesh out
> the requirements for it.

== and hashing for methods can be quite useful for things like cache
keys. (E.g., a dict mapping callable+args -> result.) I'm sure people
are using it. So I think simply removing it would be pretty
disruptive.

I can't think of any cases where == and hashing are useful for methods
on *mutable objects*, which is that case where it matters whether the
'self' comparison uses == or 'is', but the method object doesn't know
whether 'self' is mutable, so it has to either work in general or not
work in general.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-Dev mailing list