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. -- https://mail.python.org/mailman/listinfo/python-list