473,785 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doc error on super(cls,self)

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()
super(Mammal,ca t1).talk2() Mammal2: Fluffy says Purr super(Animal,ca t1).talk2() AttributeError: 'super' object has no attribute 'talk2' Cat.__mro__

(<class '__main__.Cat'> , <class '__main__.Felin e'>,
<class '__main__.Mamma l'>, <class '__main__.Mamma l2'>,
<class '__main__.Anima l'>, <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

Jul 18 '05 #1
2 1789
David MacQuigg <dm*@gain.com > wrote in message news:<pd******* *************** **********@4ax. com>...
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.


Aha! Now I see why for a while in the past I thought 'super' was returning
the superclass: I had read the documentation!

The sentence you report here is clearly WRONG and misleading, since 'super'
returns a 'super object' which is a descriptor acting more or less as a proxy
to the methods in the MRO. 'super' by no means is returning the superclass.
So please submit the documentation bug. If nobody has already done that,
I will volunteer to write a tutorial on 'super', since it is rather tricky
and terribly documented in the standard docs.

Michele Simionato
Jul 18 '05 #2
On 11 Jun 2004 21:04:40 -0700, mi************* **@poste.it (Michele
Simionato) wrote:
David MacQuigg <dm*@gain.com > wrote in message news:<pd******* *************** **********@4ax. com>...
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.


Aha! Now I see why for a while in the past I thought 'super' was returning
the superclass: I had read the documentation!

The sentence you report here is clearly WRONG and misleading, since 'super'
returns a 'super object' which is a descriptor acting more or less as a proxy
to the methods in the MRO. 'super' by no means is returning the superclass.
So please submit the documentation bug. If nobody has already done that,
I will volunteer to write a tutorial on 'super', since it is rather tricky
and terribly documented in the standard docs.


I will submit the bug report.

I think a tutorial would be very helpful. The only clear (but
lengthy) explanation I have found is GvR's paper at
http://python.org/2.2.3/descrintro.html#cooperation (see "Cooperativ e
methods and super" pp.14-18 in the printed version) I've tried to
condense this into a brief summary in my OOP chapter at
http://ece.arizona.edu/~edatools/Python/PythonOOP.doc (see "Super
Calls" on p.14-15). I could add your tutorial as an example or
exercise, or link to your website, if you have a relatively permanent
place.

-- Dave

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2331
by: Kerim Borchaev | last post by:
Hello! Always when I use "super" I create a code duplication because class used as first arg to "super" is always the class where the method containing "super" was defined in: ''' class C: def method(self): super(C, self).method() '''
0
1240
by: Michele Simionato | last post by:
Here is an idea for a nicer syntax in cooperative method calls, which is not based on Guido's "autosuper" example. This is just a hack, waiting for a nicer "super" built-in ... Here is example of usage: from cooperative import Cooperative class B(Cooperative): def print_(self):
2
6118
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line #80 and line # 38 are the first line offenders. --> --> -->
10
2136
by: Chris Green | last post by:
Good day, I've done a bit of searching in the language reference and a couple pages referring the behavior of super() but I can't find any discussion of why super needs the name of the class as an argument. Feel free to point me into the bowels of google if this has been discussed to death already. super(self).method() seems like super could just do the right thing...
6
341
by: David Hirschfield | last post by:
I'm having trouble with the new descriptor-based mechanisms like super() and property() stemming, most likely, from my lack of knowledge about how they work. Here's an example that's giving me trouble, I know it won't work, but it illustrates what I want to do: class A(object): _v =
5
1439
by: Erwan Adam | last post by:
Hi all, I have a problem with the use of descriptors and super. The file is : # --------------- class Desc(object): def __init__(self, class_name): self.class_name = class_name
12
344
by: iu2 | last post by:
Hi I'm trying to make a method call automatically to its super using this syntax: class A: chained = def pr(self): print 'Hello from A'
18
2506
by: Richard Szopa | last post by:
Hello all, I am playing around w/ Python's object system and decorators and I decided to write (as an exercise) a decorator that (if applied to a method) would call the superclass' method of the same name before doing anything (initially I wanted to do something like CLOS :before and :end methods, but that turned out to be too difficult). However, I cannot get it right (specially, get rid of the eval). I
1
2105
by: lpyth | last post by:
class abc: def __init__(self,x,y,z): self.x = x self.y = y self.z = z def add(self): c = self.x + self.y + self.z
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.