Class Variable Access and Assignment

Paul Rubin http
Sun Nov 6 01:27:00 CET 2005


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> But do you want x += y to work for immutable objects as well? Then
> __iadd__ cannot be a statement, because x can't be modified in place.

It never occurred to me that immutable objects could implement __iadd__.
If they can, I'm puzzled as to why.  

> While I am enjoying the hoops people are jumping through to modify the
> language so that b.a += 2 assigns b.a in the same scope as it was
> accessed, I'm still rather perplexed as to why you would want that
> behaviour.

Weren't you the one saying += acting differently for mutables and
immutables was a wart?  If it's such a wart, why are do you find it so
important to be able to rely on the more bizarre consequences of the
wartiness?  Warts should be (if not fixed) avoided, not relied on.



More information about the Python-list mailing list