[Python-Dev] About [].append == [].append

Ivan Pozdeev vano at mail.mipt.ru
Thu Jun 21 11:58:05 EDT 2018


On 21.06.2018 16:39, Steven D'Aprano wrote:
> On Thu, Jun 21, 2018 at 02:33:27PM +0300, Ivan Pozdeev via Python-Dev wrote:
>
>> First, tell us what problem you're solving.
> You might not be aware of the context of Jereon's question. He is the
> author of PEP 579 and 580, so I expect he's looking into implementation
> details of the CPython builtin functions and methods.

I see.

`pythonobject.c:method_richcompare' compares .im_func and .im_self . 
Bound builtin methods should do the same, obviously -- preferrably, even 
use the same code.

>
> https://www.python.org/dev/peps/pep-0579/
>
> https://www.python.org/dev/peps/pep-0580/
>
>
>> 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_?
> That's a red-herring, because CPython already defines an unambiguous
> notion of method equality. The problem is that the notion depends on
> whether the method is written in Python or not, and that seems like a
> needless difference.
>
>
>> 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.
> How do you come to that conclusion? If "refuse the temptation to guess"
> applied here, we couldn't do this:
>
> py> "".upper == "".upper
> True
>
> (by your reasoning, it should raise an exception).
>
> Note the contrast in treatment of strings with:
>
> py> [].append == [].append
> False
>
> (The reason is that "" is cached and reused, and the empty string is
> not.)
>
>
>> On 21.06.2018 14:25, Jeroen Demeyer wrote:
> [...]
>
>>> I think that comparing using "==" is the right thing to do because
>>> "is" is really an implementation detail.
> +1
>
>

-- 
Regards,
Ivan



More information about the Python-Dev mailing list