is implemented with id ?

Dave Angel d at davea.name
Wed Sep 5 14:40:06 EDT 2012


On 09/05/2012 02:27 PM, Terry Reedy wrote:
> On 9/5/2012 8:48 AM, Ramchandra Apte wrote:
>
>> Seeing this thread, I think the is statment should be removed.
>> It has a replacement syntax of id(x) == id(y)
>
> The thread is wrong then.
>
> If the implementation reuses ids, which CPython does,
> <expression-1> is <expression-2>
> must be implemented as
>
> internal-tem1 = <expression-1>
> internal-tem2 = <expression-2>
> id(internal-tem1) == id(internal-tem2)
>
> in order to ensure that the two objects exist simultaneously,
> so that the id comparison is valid.
>
> > and "a==True" should be automatically changed into memory comparison.
>
> I have no idea what that means.
>

It's probably a response to Steve's comment

"""

In general, you almost never need to care about IDs and object identity. 
The main exception is testing for None, which should always be written as:

    if x is None
"""

 Somehow he substituted True for None.  Anyway, if one eliminates "is"
then Steve's comment wouldn't apply.

-- 

DaveA




More information about the Python-list mailing list