[Python-Dev] inplace operators and __setitem__

Phillip J. Eby pje at telecommunity.com
Wed Sep 28 17:41:46 CEST 2005

At 05:15 PM 9/28/2005 +0200, Reinhold Birkenfeld wrote:
>Okay. I assume that we must accept that
>s = set()
>t = (s,)
>t[0] |= set([1])
>changes s in spite of raising TypeError.

There are lots of operations that can be partially completed before raising 
an error, so I'm not sure why this case would be special.

Sets do have an update() method, however, and it's unambiguous as to being 
an in-place update.  The code above would be clearer using it, and produce 
no errors:

    s = set()
    t = (s,)

More information about the Python-Dev mailing list