frozenset can be altered by |=

Chris Angelico rosuav at gmail.com
Mon Nov 22 08:57:39 EST 2021


On Tue, Nov 23, 2021 at 12:52 AM David Raymond <David.Raymond at tomtom.com> wrote:
> It is a little confusing since the docs list this in a section that says they don't apply to frozensets, and lists the two versions next to each other as the same thing.
>
> https://docs.python.org/3.9/library/stdtypes.html#set-types-set-frozenset
>
> The following table lists operations available for set that do not apply to immutable instances of frozenset:
>
> update(*others)
> set |= other | ...
>
>     Update the set, adding elements from all others.

Yeah, it's a little confusing, but at the language level, something
that doesn't support |= will implicitly support it using the expanded
version:

a |= b
a = a | b

and in the section above, you can see that frozensets DO support the
Or operator.

By not having specific behaviour on the |= operator, frozensets
implicitly fall back on this default.

ChrisA


More information about the Python-list mailing list