cooperation of buitlin methods usingtsuper

Michele Simionato mis6 at
Thu Jul 3 16:52:44 CEST 2003

> In <2259b0e2.0307020855.478300c2 at> Michele Simionato wrote:
> > Matthias Oberlaender <matthias.oberlaender at> 
> wrote in message news:<bduh36$rgn$1 at>...> I would like  
> to adopt the cooperation paradigm in conjunction with builtin 
> > > methods and operators, such as len, iter, +, * etc. 
> > 
> > Fine.
> > 
> > > But the direct approach does not work with the current implementation of 
> > > super. For example, 'len(super(Y, y)' will always result in 'len() of 
> > > unsized object'.
> > 
> > Of course, it must give an error! I think you do not understand how 
> > super works. But don't worry, that's quite common ;)
> Oh, wait a minute. I think this "of course" is a bit presumptuous. 

Uhm... I do realize now that what I wrote sounds quite presumptuous
It was not my intention. The "of course" refers to the current
of ``super`` which does not do what you ask for. To me this was well
because of recent threads on the subject by Bjorn Pettersen:*

You see that for sure you are not the only one who is confused about
``super`` and there are dark corners about it. I myself do not know
nothing about its

> > 
> > I think you should re-read the documentation and
> > google on the newsgroup for 'super'. The use case
> > for super is in multiple inheritance, as in this example:
> > 
> > class B(object):
> >     def __len__(self):
> >       print 'called B.__len__'   return 1111
> >     
> > class C(B):
> >   def __len__(self):
> >       print 'called C.__len__'
> >       return super(C,self).__len__()
> This is exactly the style of syntax I want to avoid! I'd rather write more 
> concisely 'len(super(C,self))'.  

I see now what's your point, which is the same of Pettersen: why 

>>> class B(object):
	def __len__(self): return 1111
>>> class C(B): pass
>>> c=C()
>>> super(C,c).__len__()

works, whereas

>>> len(super(C,c))
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in ?
TypeError: len() of unsized object

does not work? As you say, the reason is that

> at least in Python 2.2.1, its is 
> a matter of fact that builtins/special method names are treated differently 
> from ordinary class methods in conjunction with super objects. Do you agree? 
> My implementation of super seems to fix this gap. Perhaps there are some 
> other people who would appreciate that too. Or are there good 
> logical/conceptual reasons againts it? This is what I would like to know.

BTW, the same is true for Python2.3b2. I always use the longest form
of ``super``,so this problems does not bother me, nevertheless I
your point.

I think you should submit the issue to python-dev; maybe there are
technical reasons such that it is necessary to treat special methods
differently and this cannot be avoided. In such a case the
documentation should report that
only the long form ``super(C,c).__len__()`` is correct and that users
not use ``len(super(C,c))`` (idem for other special methods).

I would also submit a bug report on sourceforge, since at the best
this is
a documentation bug. It does not seem to have been reported before and
already bitten at least two persons on, therefore it should be
known to the developers  


More information about the Python-list mailing list