Why this apparent assymetry in set operations?
Neil Cerutti
mr.cerutti at gmail.com
Tue Jan 15 11:51:27 EST 2008
On Jan 15, 2008 11:07 AM, Skip Montanaro <skip at pobox.com> wrote:
> > > Why is that? Doesn't the |= operator essentially map to an update() call?
> >
> > No, according to 3.7 Set Types, s | t maps to s.union(t).
>
> I was asking about the |= assignment operator which according to the
> docs *does* map to the update method.
Oops! You're right. That's surprising.
This inconsistency is due to the c implementation.
Internally, |= maps to the c function set_ior, while .update(...) maps
to set_update.
Both eventually call set_update_internal, which works fine when the
operand is not a set.
But set_ior specifically punts non-sets before calling set_update_internal.
So this is a bug in set_update or in set_ior. They can't both be
right.
--
Neil Cerutti <mr.cerutti+python at gmail.com>
More information about the Python-list
mailing list