2011/7/8 Cesare Di Mauro <cesare.di.ma...@gmail.com>:
> I fully agree. It's not an issue, but an implementation-specific detail
> which programmers don't have to assume always true.
>
> CPython can be compiled without "smallints" (-5..256, if I remember
> correctly) caching. There's a #DEFINE that can be disabled, so EVERY int (or
> long) will be allocated, so using the is operator will return False most of
> the time (unless you are just copied exactly the same object).
>
> The same applies for 1 character strings, which are USUALLY cached by
> CPython.

But the problem here is not object cache, but preservation of object identity,
which is quite different.
Python containers are supposed to keep the objects you put inside:

myList.append(x)
assert myList(-1) is x

myDict[x] = 1
for key in myDict:
    if key is x:
        ...

-- 
Amaury Forgeot d'Arc
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to