473,597 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

oddness in super()

Ok, this works in Python on Windows, but here on Linux, with Python 2.4.1, I'm
getting an error.

The docs say:

A typical use for calling a cooperative superclass method is:

class C(B):
def meth(self, arg):
super(C, self).meth(arg)

However, when I try this, which works on windows, with ActiveState
ActivePython 2.4.0...

class RemGuiFrame(Rem Glade.RemFrame) :
"""This class is the top-level frame for the application."""

def __init__(self, *args, **kwds):
"Class constructor."
# Constructor chaining
super(RemGuiFra me, self).__init__( *args, **kwds)

...on linux I get this...

[msoulier@piglet pysrc]$ ./RemGui.py
Traceback (most recent call last):
File "./RemGui.py", line 206, in ?
frame_1 = RemGuiFrame(Non e, -1, "")
File "./RemGui.py", line 30, in __init__
super(RemGuiFra me, self).__init__( *args, **kwds)
TypeError: super() argument 1 must be type, not classobj

Why the difference? Is Python portability overrated? Is this a bug?

I'm confused.

Mike

--
Michael P. Soulier <ms******@digit altorque.ca>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
Jabber: ms******@digita ltorque.ca

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFCtH6hKGq Cc1vIvggRAqJAAJ 9gV/XDjyOGYAgC4f4xU 3U7wuRKXwCfRW/K
InT8GPVSfY3vIp3 43BJlqlg=
=utmQ
-----END PGP SIGNATURE-----

Jul 19 '05 #1
2 2538
Michael P. Soulier wrote:
Why the difference? Is Python portability overrated? Is this a bug?


Certainly a bug - but not in python. The super-method works for
new-style classes only.

The attached script reproduces your observed behaviour. So kit seems
that whatever toolkit you use, it uses new-style classes on windows, and
old-style ones on linux.

Regards,

Diez

class Foo(object):
def __init__(self):
print "I'm Foo"

class Bar:
def __init__(self):
print "I'm Bar"
class SubFoo(Foo):
def __init__(self):
super(SubFoo, self).__init__( )

class SubBar(Bar):
def __init__(self):
super(SubBar, self).__init__( )

SubFoo()
SubBar()
Jul 19 '05 #2
Michael P. Soulier wrote:
Ok, this works in Python on Windows, but here on Linux, with Python 2.4.1, I'm
getting an error.

The docs say:

A typical use for calling a cooperative superclass method is:

class C(B):
def meth(self, arg):
super(C, self).meth(arg)

However, when I try this, which works on windows, with ActiveState
ActivePython 2.4.0...

class RemGuiFrame(Rem Glade.RemFrame) :
"""This class is the top-level frame for the application."""

def __init__(self, *args, **kwds):
"Class constructor."
# Constructor chaining
super(RemGuiFra me, self).__init__( *args, **kwds)

...on linux I get this...

[msoulier@piglet pysrc]$ ./RemGui.py
Traceback (most recent call last):
File "./RemGui.py", line 206, in ?
frame_1 = RemGuiFrame(Non e, -1, "")
File "./RemGui.py", line 30, in __init__
super(RemGuiFra me, self).__init__( *args, **kwds)
TypeError: super() argument 1 must be type, not classobj

Why the difference?
You are in the best position to answer that; you have access to the
source code of the place where the problem occurs (RemGui.py), in both a
"working" instance and a non-"working" instance, so you can (a) read it
(b) debug it with a debugger, or insert print statements e.g. print
repr(RemGuiFram e), repr(RemGlade.R emFrame)

You have already noted two variables, OS Windows/Linux, and Python
2.4.[01]). Are there any others? Perhaps RemGlade.RemFra me comes from a
3rd party library and there's a version difference.
Is Python portability overrated?
No. Please stop baying at the moon, and dig out some evidence.
Is this a bug?
Is *what* a bug?

Is "it" a bug in what? Windows? Linux? Python 2.4.0? Python 2.4.1? 3rd
party code? your code?

=====

I've never used "super" before, I'm only vaguely aware what it could be
useful for, and what a "cooperativ e superclass method" might be, and I
don't have access to your source code, nor to Linux ... but let's just
see what can be accomplished if you drag yourself away from that moonlit
rock and start digging:

First (1) Ooooh what a helpful error message! What is a "classobj"?

Let's RTFM: Hmmm don't tell X** L** but there's no entry for "classobj"
in the index. But wait, maybe that's geekspeak for "class object" ...
two or three bounces of the pogo-stick later we find this:

"""
Class Types
Class types, or ``new-style classes,'' are callable. These objects
normally act as factories for new instances of themselves, but
variations are possible for class types that override __new__(). The
arguments of the call are passed to __new__() and, in the typical case,
to __init__() to initialize the new instance.

Classic Classes
Class objects are described below. When a class object is called, a new
class instance (also described below) is created and returned. This
implies a call to the class's __init__() method if it has one. Any
arguments are passed on to the __init__() method. If there is no
__init__() method, the class must be called without arguments.
"""

(2) Well fancy that... "type" kinda sorta means "new", "classobj" kinda
sorta means "old"! Now let's re-read the bit about super in TFM:

"""
super() only works for new-style classes
"""

(3) So let's check out our tentative hypothesis:
"""
class Bold:
def __init__(self):
print "Bold"

class Bnew(object):
def __init__(self):
print "Bnew"

class Cold(Bold):
def __init__(self):
print "Cold", repr(Cold), "derives from", repr(Bold)
super(Cold, self).__init__( )
print "Cold OK"

class Cnew(Bnew):
def __init__(self):
print "Cnew", repr(Cnew), "derives from", repr(Bnew)
super(Cnew, self).__init__( )
print "Cnew OK"

cnew = Cnew()
cold = Cold()
"""

which when run on Python 2.4.1 on a Windows box produces this result:
"""
Cnew <class '__main__.Cnew' > derives from <class '__main__.Bnew' >
Bnew
Cnew OK
Cold <class __main__.Cold at 0x00ADF750> derives from <class
__main__.Bold at 0x00ADF630>
Traceback (most recent call last):
File "C:\junk\soulie r.py", line 22, in ?
cold = Cold()
File "C:\junk\soulie r.py", line 12, in __init__
super(Cold, self).__init__( )
TypeError: super() argument 1 must be type, not classobj

"""

Funny that, the class repr()s are different; not in a meaningful way,
but the mere difference indicates the classes are products of different
manufacturers.

(4) Ooooh! How old is the Linux copy of that 3rd party library?

(5) Looks like the bug is in RemGui.py -- it is calling super() with an
invalid argument. No apparent Python portability problems.

I'm confused.


Confession is good for the soul. However true confession is even better
for the soul. Please come up with a better description. :-)

===

I hope these self-help hints are useful with your next "confusion" .

Cheers,
John
Jul 19 '05 #3

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

Similar topics

4
2318
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() '''
2
1667
by: Clarence Gardner | last post by:
The super object is considered a solution to the "diamond problem". However, it generally requires that the ultimate base class know that it is last in the method resolution order, and hence it should not itself use super (as well as supplying the ultimate implementation of an overridden method.) However, a problem comes up if that ultimate base class is also the base class for another which inherits from it and another independent base...
11
5021
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in function on pages 89-90. Based on the example on page 90, I wrote this test code : class A(object): def test(self): print 'A'
0
1500
by: Delaney, Timothy C (Timothy) | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195 This is a new version of super that automatically determines which method needs to be called based on the existing stack frames. It's much nicer for writing cooperative classes. It does have more overhead, but at this stage I'm not so concerned about that - the important thing is it actually works. Note that this uses sys._getframe() magic ...
6
2003
by: Steven Bethard | last post by:
When would you call super with only one argument? The only examples I can find of doing this are in the test suite for super. Playing around with it: py> class A(object): .... x = 'a' .... py> class B(A): .... x = 'b' ....
3
1790
by: John Abel | last post by:
Hi, I'm running Python 2.3.5/2.4.2 on OSX 10.4.2, and am trying to run CGI scripts using the builtin Apache. For ease, I've symlinked my custom modules into the /Library/Python/2.3/site-packages directory, and they import OK via command line python. However, when I perform the import from a cgi script, python fails to find the module. It is definately something to do with the symlink, as the CGI works OK if I copy the directory into...
9
2191
by: Mike Krell | last post by:
I'm reading Alex Martelli's "Nutshell" second edition. In the section called "Cooperative superclass method calling", he presents a diamond inheritance hierachy: class A(object): def met(self): print "A.met" class B(A): def met(self): print "B.met"
4
1715
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
1
1503
by: cedarmillxing215 | last post by:
The oddness is on the last line of code. This is stripped down as far as I could figure, and I provide several similar examples that work as expected. I have no idea whether this is a compiler bug or my not understanding how the << overload is chosen. -Chris -------------------- #include <iostream>
0
7979
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...
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8262
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...
1
5847
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
3937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2409
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
1
1497
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
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.