D
David MacQuigg
I think there is a documentation error in both the Library Reference
section 2.1 and the Python 2.2 Quick Reference page 19. The
explanation for this function is:
super( type[, object-or-type])
Returns the superclass of type.
I could not get this function to work right until I realized that it
is searching the entire MRO, not just the superclasses of 'type'.
Here is a simple experiment to show the difference.
## Animal -> Mammal -> Feline -> Cat
## talk1() talk1() talk1()
## \ - - - -> Mammal2 - - - - - - -> /
## talk2()(<class '__main__.Cat'>, <class '__main__.Feline'>,
<class '__main__.Mammal'>, <class '__main__.Mammal2'>,
<class '__main__.Animal'>, <type 'object'>)
The first call finds talk2, even though it is *not* in a superclass of
Mammal. The second call fails, because talk2 is not found in any
class above Animal in the MRO.
I think a better explanation would be:
super(cls,self).meth(arg)
This calls method 'meth' from a class in the MRO (Method Resolution
Order) of 'self'. The selected class is the first one which is above
'cls' in the MRO and which contains 'meth'.
I would like to get some feedback before submitting this as a bug.
-- Dave
section 2.1 and the Python 2.2 Quick Reference page 19. The
explanation for this function is:
super( type[, object-or-type])
Returns the superclass of type.
I could not get this function to work right until I realized that it
is searching the entire MRO, not just the superclasses of 'type'.
Here is a simple experiment to show the difference.
## Animal -> Mammal -> Feline -> Cat
## talk1() talk1() talk1()
## \ - - - -> Mammal2 - - - - - - -> /
## talk2()(<class '__main__.Cat'>, <class '__main__.Feline'>,
<class '__main__.Mammal'>, <class '__main__.Mammal2'>,
<class '__main__.Animal'>, <type 'object'>)
The first call finds talk2, even though it is *not* in a superclass of
Mammal. The second call fails, because talk2 is not found in any
class above Animal in the MRO.
I think a better explanation would be:
super(cls,self).meth(arg)
This calls method 'meth' from a class in the MRO (Method Resolution
Order) of 'self'. The selected class is the first one which is above
'cls' in the MRO and which contains 'meth'.
I would like to get some feedback before submitting this as a bug.
-- Dave