[Python-Dev] About [].append == [].append (original) (raw)

INADA Naoki songofacandy at gmail.com
Thu Jun 21 10:16:26 EDT 2018


2018年6月21日(木) 20:27 Jeroen Demeyer <J.Demeyer at ugent.be>:

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.

I think "is" is correct because "bound to which object" is essential for bound (instance) methods.

Consider

>>> (10000).bitlength == (10000).bitlength True >>> (10000).bitlength == (10000+0).bitlength False

I'm OK for this difference. This comparison is what people shouldn't do, like 'id(10000) == id(10000+0)'

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?

I think changing this may break some tricky code. Is it really worth enough to change?

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/songofacandy%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180621/c3547c36/attachment-0001.html>



More information about the Python-Dev mailing list