# generic class A(object): def __iadd__(self, other): return NotImplemented class B(object): def __radd__(self, other): return 123 a = A() b = B() a += b print a # lists class NotList(object): def __init__(self, iterable=None): self.l = iterable is not None and list(iterable) or list() def extend(self, iterable): self.l.extend(iterable) def __iter__(self): return iter(self.l) def __radd__(self, other): print "__radd__" if not isinstance(other, (list, NotList)): return NotImplemented return NotList(list(other) + self.l) def __repr__(self): return 'NotList(%r)' % self.l l_too = l = list('a') nl = NotList([1,2,3]) l += nl print 'type(l) is NotList', type(l) is NotList print 'type(l_too) is list', type(l_too) is list # $ py23 list_iadd.py # 123 # __radd__ # type(l) is NotList True # type(l_too) is list True # $ py24 list_iadd.py # 123 # __radd__ # type(l) is NotList True # type(l_too) is list True # $ py25 list_iadd.py # 123 # __radd__ # type(l) is NotList True # type(l_too) is list True # $ jython list_iadd.py # 2.3a0 java1.5.0_09 # NotImplemented # type(l) is NotList False # type(l_too) is list True