literals optimization (was Re: append on lists)

Grant Edwards grante at
Tue Sep 16 18:56:53 CEST 2008

On 2008-09-16, Maric Michaud <maric at> wrote:
> Le Tuesday 16 September 2008 18:26:38 Grant Edwards, vous avez écrit :
>> I was asking where in the specification
>> <> it says that all expressions that
>> return something, return a
>> new object.  
> I never said this,

Here's what you wrote:

>>>> all expressions that return something, return a new object.
>>> That's not _quite_ true:
>>> >>> a=1
>>> >>> b=a.__add__(0)
>>> >>> a is b
>>> True
>>This is implementation specific, the specification of the
>>language says that it should be false,

You made a statement, I pointed out a degenerate case where
that statement was violated.  You replied that that my
counter-example violated the language specification.  I read
that as a claim that your original statement was part of the
language specification.

If that's not what you meant, I aplogize.  I'll should have
been more specific and asked "in the counter example above,
where in the laguage specification does it shat that 'a is b'
is supopsed to be false?"

> I said it's the spirit of python APIs, with some noticeable 
> exceptions (see my first post). But for this case
> specifically, a + b *should* return a new object, see the 
> documentation of __add__ and __iadd__ special methods, it's
> clearly stated.

I'll take a look...

> The fact that an integer with value "1" is always the same
> integer in some implementation is unrelated to the original
> problem.

Not if it results in a violation of something in the language

Grant Edwards                   grante             Yow! Pardon me, but do you
                                  at               know what it means to be
                                 TRULY ONE with your BOOTH!

More information about the Python-list mailing list