[Python-Dev] About [].append == [].append (original) (raw)
Ivan Pozdeev vano at mail.mipt.ru
Thu Jun 21 07:33: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 ]
First, tell us what problem you're solving.
Strictly speaking, bound methods don't have an unambiguous notion of equality:
are they equal if they do the same thing, or of they do they same thing on the same object?
The result that you're seeing is a consequence of that same dichotomy in the minds of the .eq designers, and Python Zen advises "In the face of ambiguity, refuse the temptation to guess." -- which is what you're suggesting.
On 21.06.2018 14:25, Jeroen Demeyer wrote:
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 In the former case, self is compared using "is" and in the latter case, it is compared using "==". I think that comparing using "==" is the right thing to do because "is" is really an implementation detail. Consider >>> (10000).bitlength == (10000).bitlength True >>> (10000).bitlength == (10000+0).bitlength False I guess that's also the reason why CPython internally rarely uses "is" for comparisons. See also: - https://bugs.python.org/issue1617161 - https://bugs.python.org/issue33925 Any opinions?
Jeroen.
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
- 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 ]