Behavior of += (was Re: [Python-Dev] Customization docs)

John Roth johnroth at ameritech.net
Wed Jun 5 17:15:59 EDT 2002


"Chris Barker" <Chris.Barker at noaa.gov> wrote in message
news:3CFE6B13.79CA4A8C at noaa.gov...
> John Roth wrote:
> > I don't see a compatability issue here, because
> > the current behavior raises an exception.
>
> Unless someone did the perverse thing I proposed in a earlier post,
and
> took advantage of the fact that the operation did, in fact, work, even
> though it raised an exception!

That's perverse enough that whoever does it deserves for their
program to fail on an upgrade.

> While I completely agree with Huaiyu's argument (though I'm not sure
the
> "increment with re-binding" is really all that useful for mutables),
and
> I think the current semantics is a minor wart, I am convinced that the
> original behavior that started this thread is a MAJOR WART (I'd call
it
> a bug). I think I have a pretty good understanding now of why it
> happens, and why it isn't trivial to change, but I think it is a very
> bad idea for an operation to raise an exception, but also be
successful!
>
> Chris
>
I thoroughly agree. Operations like += should be atomic -
they should either succeed or fail. The remaining question is
simply whether it goes to the bug list or to a PEP.

John Roth





More information about the Python-list mailing list