[Python-Dev] About [].append == [].append (original) (raw)
Ivan Pozdeev vano at mail.mipt.ru
Thu Jun 21 17:04:55 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 ]
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.
In my previous message, I meant that if they do have that logic, the right way is what `method_richcompare' does. And that was apparently what the method's author (that you might be familiar with) was thinking in https://github.com/python/cpython/commit/47b9ff6ba11fab4c90556357c437cb4feec1e853 -- and even then and there, they were hesitant about the feature's usefulness.
But Serhiy has just disproven that that is the right way which looks like the final nail into its coffin.
On Thu, Jun 21, 2018, 12:55 Serhiy Storchaka <storchaka at gmail.com_ _<mailto: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 <mailto: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
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/vano%40mail.mipt.ru
-- Regards, Ivan
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180622/95ee2613/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 ]