[Python-Dev] About [].append == [].append (original) (raw)
Guido van Rossum gvanrossum at gmail.com
Thu Jun 21 16:40:27 EDT 2018
- Previous message (by thread): [Python-Dev] About [].append == [].append
- Next message (by thread): [Python-Dev] About [].append == [].append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
On Thu, Jun 21, 2018, 12:55 Serhiy Storchaka <storchaka at gmail.com> wrote:
21.06.18 14:25, Jeroen Demeyer пише: > Currently, we have: > > >>> [].append == [].append > False > > However, with a Python class: > > >>> class List(list): > .... def append(self, x): super().append(x) > >>> List().append == List().append > True
I think this is a bug. These bound methods can't be equal because they have different side effect. The use case for using "is" for self is described by the OP of issue1617161. I don't know use cases for using "==". There is a related problem of hashing. Currently bound methods are not hashable if self is not hashable. This makes impossible using them as dict keys.
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180621/649e8e3e/attachment.html>
- Previous message (by thread): [Python-Dev] About [].append == [].append
- Next message (by thread): [Python-Dev] About [].append == [].append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]