Python Source Code Beautifier

Gabriel Genellina gagsl-py2 at
Wed Mar 7 18:13:28 CET 2007

En Wed, 07 Mar 2007 10:29:29 -0300, Alan Franzoni  
<alan.franzoni_invalid at geemail.invalid> escribió:

> Il Tue, 06 Mar 2007 01:55:54 -0300, Gabriel Genellina ha scritto:

> If we rely on duck typing, by the way, we may encounter two types  
> quacking
> like ducks, flying like ducks, but in fact acting as slightly different
> ducks. I should remember as well, when designing a container type that I
> want to use in place of a list, to carefully craft an __iadd__ method  
> which
> works just like the a list's own __iadd__ method; if I forget, I may
> introduce a subtle error.

I'm not sure of your concerns. If you want to provide your own container  
that mimics a list, there are a lot more things to consider than __iadd__  
(See the UserList class or this ListMixin recipe:

__iadd__, in general, is not *required* to modify the instance in place  
(but should try to do that, if possible). After this code:
	b = a
	a += c
you can't assert than a and b both refer to the *same* object, as before.  
If you need that, don't use += at all. (For a generic object, I mean. The  
built-in list "does the right thing", of course)

Gabriel Genellina

More information about the Python-list mailing list