Is this a super bug?

Michele Simionato mis6 at pitt.edu
Mon Apr 21 22:58:55 CEST 2003


> "Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message 
> news:<mailman.1050811779.16487.python-list at python.org>...
> 
> > <snip> this is the sequence that "should" happen:
> > 1  super(ff, f)[0]  # f == self
> > 2  superinst(type:<class ff>, obj:f)[0]
> > 3  si.__getitem__(0)
> > 4    si.__getattr__('  getitem  ')
> > 5    .. return str.__dict__['  getitem  '].__get__(f)
> > 6    boundmethod(str.__getitem__, f)
> > 7  bmeth(0)
> > 8   'a'
> 

This is the sequence I would expect:

1. super(ff, f)[0] 
2. superinst(type:<class ff>, obj:f)[0]
3. type(si).__getitem__(si,0)
4. <type 'super'>.__getitem__(si,0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: type object 'super' has no attribute '__getitem__'

Nevertheless one gets

>>> super(ff,f)[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsubscriptable object

Therefore I am confused :-(

On the other hand if I do

>>> class C(object): pass
...
>>> c=C()
>>> c[0] # I would expect to be C.__getitem__(c,0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unindexable object

I get the unindexable error, not the attribute error. The
problem has nothing to do with super, but I agree there is
something strange in how __getitem__ is invoked.
Maybe the problem is simply in the displayed error
message: displaying 

  AttributeError: <class '__main__.C'> has no attribute '__getitem__'

could be more confusing for newbies than 

  TypeError: unindexable object

and therefore the AttributeError has been changed to a TypeError.

Is this the answer ? Or am I entirely wrong on my understanding of
__getitem__ ?

                                   Michele




More information about the Python-list mailing list