How to extend a tuple of tuples?

Random832 random832 at fastmail.com
Tue Sep 13 10:26:40 EDT 2016


On Mon, Sep 12, 2016, at 17:29, Chris Angelico wrote:
> old_id = id(a)
> a += something
> if id(a) == old_id:
>     print("We may have an optimization, folks!")
> 
> But that can have false positives. If two objects do not concurrently
> exist, they're allowed to have the same ID number.

But the two objects do concurrently exist, from the time __iadd__ is
evaluated until the time when a is assigned, in the formal semantics of
this code. Allowing them to not concurrently exist is, effectively,
precisely the optimization being discussed.



More information about the Python-list mailing list