subclassing a module: misleading(?) error message

Erik Johnson ejatsomewhere.com
Thu Jan 4 21:49:22 CET 2007


I ran into a problem I didn't understand at first. I got part of it figured
out. Let me first demonstrate the original problem:

> cat Super.py

class Super(object):
    def __init__(self):
        self._class = 'Super'
    def hello(self):
        print "%s says 'Hello'" % self._class
> cat Sub.py

import Super

class Sub(Super):
    def __init__(self):
        self._class = 'Sub'
>
> python
Python 2.3.4 (#1, Feb  7 2005, 15:50:45)
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Super import Super
>>> from Sub import Sub
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "Sub.py", line 4, in ?
    class Sub(Super):
TypeError: function takes at most 2 arguments (3 given)
>>>

My question is NOT "What's wrong here?"
(The answer to that is that the import in Sub.py should be:  from Super
import Super
i.e., I tried to use the module itself where I meant to subclass the class
defined in that module).

My questions are:

Why does python complain about a function here? (it's a class definition
statement, right?)
Is there really a function being called here?
If so:
    What function was called?
    What two arguments is it expecting?
    What three were given?

Thanks,
-ej





More information about the Python-list mailing list