473,480 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Create 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(RemGlade.RemFrame):
"""This class is the top-level frame for the application."""

def __init__(self, *args, **kwds):
"Class constructor."
# Constructor chaining
super(RemGuiFrame, 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(None, -1, "")
File "./RemGui.py", line 30, in __init__
super(RemGuiFrame, 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******@digitaltorque.ca>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
Jabber: ms******@digitaltorque.ca

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

iD8DBQFCtH6hKGqCc1vIvggRAqJAAJ9gV/XDjyOGYAgC4f4xU3U7wuRKXwCfRW/K
InT8GPVSfY3vIp343BJlqlg=
=utmQ
-----END PGP SIGNATURE-----

Jul 19 '05 #1
2 2528
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(RemGlade.RemFrame):
"""This class is the top-level frame for the application."""

def __init__(self, *args, **kwds):
"Class constructor."
# Constructor chaining
super(RemGuiFrame, 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(None, -1, "")
File "./RemGui.py", line 30, in __init__
super(RemGuiFrame, 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(RemGuiFrame), repr(RemGlade.RemFrame)

You have already noted two variables, OS Windows/Linux, and Python
2.4.[01]). Are there any others? Perhaps RemGlade.RemFrame 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 "cooperative 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\soulier.py", line 22, in ?
cold = Cold()
File "C:\junk\soulier.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
2306
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:...
2
1662
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...
11
5010
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...
0
1482
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....
6
1993
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'...
3
1782
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...
9
2185
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...
4
1704
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
1491
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...
0
6908
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...
0
7043
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,...
1
6737
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...
0
5336
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,...
1
4776
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...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
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...

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.