Is this a super bug?
Michele Simionato
mis6 at pitt.edu
Mon Apr 21 11:10:25 EDT 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'
I don't understand what you are trying to say here ...
> well, the transition from 3 to 4 doesn't happen which surprised me a
> little. What surprised me more was that I couldn't get getattribute
> to be called either (neither in the class or its metaclass... I've only
> got 2.3a2, and I read a note about this not working before a4. Is this
> what is happening? If not, the only other reason I could see would be
> from the refMan 5.3.2, "The primary must evaluate to an object of a
> sequence or mapping type." If that is the case, then I still think it's
> a super bug, i.e. there is no reason super should assume that it's not
> "going to be" a sequence, in fact the direct superclass of ff is a
> sequence. To fix it simply add:
>
> def getitem (self, v):
> m = self. getattr (' getitem ')
> return m(v)
>
> to the definition of super.
You may do that, but I don't like it. I like the fact that
super(cls,self)[index]
is *not* equivalent to
super(cls,self).__getitem__(index)
The present behaviour is the natural one, when you realize that super
objects are attribute descriptors. In other words:
super(cls,self) is *not* self
In you case 'self' is a string and has a __getitem__ method; nevertheless,
since super(cls,self) is a descriptor and not a string, I would not expect
it to have a __getitem__ method, nor the other methods of a string.
What happens in reality (disclaimer: I don't know nothing about the C
implementation, I am guessing here) is that super(cls,self) has a
__getattribute__ method that call the methods of the string object: the
fact that you can write
super(cls,self).__getitem__(index)
does *not* means that super(cls,self) has a __getitem__ method.
I agree this can be confusing at first. The solution would be to
document ``super`` and the attribute descriptors.
Maybe one of these days I will collect my notes and fill this gap,
but this would require at least 20-30 pages, so it would take some
time ...
Hope this helps,
--
Michele Simionato - Dept. of Physics and Astronomy
210 Allen Hall Pittsburgh PA 15260 U.S.A.
Phone: 001-412-624-9041 Fax: 001-412-624-9163
Home-page: http://www.phyast.pitt.edu/~micheles/
More information about the Python-list
mailing list