[Python-Dev] About [].append == [].append
Serhiy Storchaka
storchaka at gmail.com
Sat Jun 23 02:11:06 EDT 2018
23.06.18 05:21, Guido van Rossum пише:
> A bound method is a fairly complicated object, and for builtin bound
> methods, the == comparison has the following definition:
> - if the `__self__` objects are not the same object, return False
> - otherwise, return True iff it's the same method (i.e. the same name /
> the same underlying C function)
>
> I think it is more important that builtin methods and Python methods
> behave the same. Should Python methods be changed to compare self with
> "is" or are we too late to make that change?
>
>
> I am not sure. It's surprising, but I fear it may be too late to change.
> Are there tests in the stdlib for this behavior?
Two tests are failed if change the current behavior. Both were added by
fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3 in issue1350060 together with
changing comparisons for methods.
https://github.com/python/cpython/commit/fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3
https://bugs.python.org/issue1350060
It changed the behavior "for consistency". But unfortunately it made it
less consistent (and broke your definition). There are different kind of
methods, and currently they have different behavior.
>>> [].append == [].append
False
>>> [].__iadd__ == [].__iadd__
True
>>> UserList().append == UserList().append
True
Seems the last two examples returned False before issue1350060.
I think changes made in issue1350060 should be reverted. See
https://github.com/python/cpython/pull/7848 . But perhaps only in the
master branch for minimizing possible breakage.
More information about the Python-Dev
mailing list