[Python-ideas] Add MutableSet.update?

Nathaniel Smith njs at pobox.com
Sat Mar 10 18:20:57 EST 2018


On Sat, Mar 10, 2018 at 2:45 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> On Sat, Mar 10, 2018 at 3:24 AM, MRAB <python at mrabarnett.plus.com> wrote:
>>
>> On 2018-03-10 01:15, Guido van Rossum wrote:
>>>
>>> Yes, you can use the |= operator instead.
>>>
>> |= is not quite the same as .update because it rebinds,
>
>
> isn't that an "in-place operator" i.e. if it's a mutable object it should
> mutate rather than rebinding?

Normally on a mutable object, |= will mutate the object in-place AND
ALSO rebind the name to the same object it started with (like writing
'x = x'). The latter part raises an error if 'x' is not a legal target
for assignment.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list