[pypy-dev] x is y <=> id(x)==id(y)
steve at pearwood.info
Sun May 5 13:20:25 CEST 2013
On 05/05/13 19:59, Armin Rigo wrote:
> Hi all,
> I'm just wondering again about some "bug" reports that are not bugs,
> about people misusing "is" to compare two immutable objects. The
> current situation in PyPy is that "is" works like "==" for ints,
> longs, floats or complexes. It does not for strs or unicodes or
I don't understand why immutability comes into this. The `is` operator is supposed to test whether the two operands are the same object, nothing more, nothing less. Immutable, or mutable, it makes no difference.
Now, it may be that *some* immutable objects may (implicitly, or explicitly) promise that you will never have two objects with the same value. For example, float might cache every object created, so that once you have created a float 23.45910234718, it will *always* be reused whenever a float with that value is needed. That would be allowed.
But if float does not cache the value, and so you have two different float objects, with different IDs, then it is absolutely wrong for PyPy to treat `is` as == instead of testing object identity.
Have I misunderstood what you are saying?
More information about the pypy-dev