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

Guido van Rossum guido at python.org
Fri Jun 22 22:21:27 EDT 2018


On Fri, Jun 22, 2018 at 6:52 PM Steven D'Aprano <steve at pearwood.info> wrote:

> On Fri, Jun 22, 2018 at 11:44:07AM -0700, Guido van Rossum wrote:
> [...]
> > > I know why it happens -- at the REPL, the interpreter uses the same
> > > object for both 17.1 instances when they're part of the same statement,
> > > but not when they're on separate lines. I just don't know whether this
> > > is desirable or not.
> > >
> >
> > But there's nothing new about that example. It's just the same as the
> issue
> > that sometimes `1 is 1` and sometimes it isn't.
>
> Sure, but this is closer to "sometimes 1 == 1 and sometimes it isn't".
> But if you're okay with it, I don't have a counter-argument.
>

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?

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180622/adac3849/attachment.html>


More information about the Python-Dev mailing list