[Python-Dev] About [].append == [].append (original) (raw)
Jeroen Demeyer J.Demeyer at UGent.be
Thu Jun 21 07:25:19 EDT 2018
- Previous message (by thread): [Python-Dev] Intent to accept PEP 561 -- Distributing and Packaging Type Information
- Next message (by thread): [Python-Dev] About [].append == [].append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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).bit_length == (10000).bit_length True (10000).bit_length == (10000+0).bit_length False
I guess that's also the reason why CPython internally rarely uses "is" for comparisons.
See also:
Any opinions?
Jeroen.
- Previous message (by thread): [Python-Dev] Intent to accept PEP 561 -- Distributing and Packaging Type Information
- Next message (by thread): [Python-Dev] About [].append == [].append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]