inconsistency with += between different types ?

Daniel Fackrell unlearned at DELETETHIS.learn2think.org
Wed Aug 7 15:41:58 EDT 2002


"Andreas Leitgeb" <Andreas.Leitgeb at siemens.at> wrote in message
news:slrnal2s2f.c05.Andreas.Leitgeb at pc7499.gud.siemens.at...
> Terry Reedy <tjreedy at udel.edu> wrote:
> > "Andreas Leitgeb" <Andreas.Leitgeb at siemens.at> wrote in message
> >> __iadd__ is SUPPOSED to modify self's attributes and then
> >> "return self"
> > Only if that is the sensible thing to do.
> See also Message <6qlm7i60dx.fsf at thetis.intevation.de> and its followups.
>
>
> > Python is not a nanny.  It's a language for consenting adults.
> Was this intended to be a killer-argument ?
>
> Why shouldn't we try to close pitfalls that seem to gain us nothing ?


I've been following this thread, but I don't think I understand where the
pitfall is.  Do you see a pitfall because those who use the __iadd__ (or any
other) special method can define it fully to their liking?  Do you want code
added to the interpreter to enforce a particular style of behavior for all
of them?

I think this would be a double loss as it would increase the size of the
interpreter while slowing it down.  If people are playing with __iadd__ or
any other special method, they should first be looking at how it typically
works, and then trying to implement behavior that makes sense for their
object.

I'm not aware of any cases yet where someone has abused __iadd__ in a way
that caused considerable confusion.

Didn't your original post request information about why the built-in
immutables and the built-in mutables behaved differently for += ?  That
would still be the case after your proposed change, due to the fact that if
__iadd__ doesn't exist, __add__ is used in its place.

--
Daniel Fackrell (unlearned at learn2think.org)
When we attempt the impossible, we can experience true growth.





More information about the Python-list mailing list