Tuple/List identity guarantees Was(Re: __iadd__ and fellows missing (Python 2.2))

Tim Peters tim.one at comcast.net
Wed Apr 17 01:30:50 EDT 2002


[Mike C. Fletcher]
> This little mental exercise all started when Tim pointed out the tuples
> _won't_ work for the pattern (well, he pointed out that there's no
> guarantee that imutable values (particularly empty tuples) will always
> be seperate objects).  So using an empty tuple for the pattern is no
> longer suitable.

It was never suitable in theory, and since it so happens that the
implementations to date usually do return the same object for "an empty
tuple", in practice it hasn't even worked by accident.

> To the best of my knowledge, there _is_ an implicit guarantee (at least,
> such a guarantee is assumed in a lot of code) that two different
> _mutable_ objects (such as lists or instances) will _always_ return
> different id values, and thus always compare unequal with "is".

This is explicitly guaranteed by the language reference manual, and, indeed,
by the same (long <wink>) sentence that also explicitly warns it's not
guaranteed for operations returning objects of immutable types.  See the
"Objects, value and types" section.

> ...
> Oh, I care deeply for the Timbot's feelings.  Six years of fighting a
> bloody guerilla war against him ;) has made me come to love the little
> floating ball of light :) (though the strange looking guy that always
> hangs out around him kinda freaks me out ;) ).

This is a burden for the three of us, Mike.

> ...
> Reminds me, where have all the optimisation challenges gone these days?
> Tim, Christian and I used to spend whole minutes on those babies, and
> now all we can do is bat around recycled debates on object identity :).

Well, the fun when out of it when people starting taking it seriously.   The
fun of the old speed battles was based on pouring unbounded effort into
shaving microseconds nobody could sanely care about.  A magnificent effort
in pursuit of an inherently worthless goal.  This was my generation's
substitute for the giddy senselessness of war <wink>.

all's-well-so-long-as-you-wake-up-drunk-ly y'rs  - tim






More information about the Python-list mailing list