[Python-Dev] py3k: TypeError: object.init() takes no parameters (original) (raw)
Alexandre Passos alexandre.tp at gmail.com
Fri Jan 16 18:04:12 CET 2009
- Previous message: [Python-Dev] py3k: TypeError: object.__init__() takes no parameters
- Next message: [Python-Dev] py3k: TypeError: object.__init__() takes no parameters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Jan 16, 2009 at 2:12 PM, Terry Reedy <tjreedy at udel.edu> wrote:
I do not understand. You know it is going to run the .init of its one and only base class, which here is object.
Because this class might be used as base of another class. Take this trivial example code (in py2.6):
class A(object): def init(self, a): #super(A, self).init(a) self.a = a print "A"
class B(object): def init(self, a): #super(B, self).init(a) self.b = a print "B"
class C(A, B): def init(self, a): super(C, self).init(a) self.c = a print "C", dir(self)
C(1)
Running the last line shows that A's constructor got called, but not B's constructor. The only way to make sure all __init__s are called in this example is by doing
class A(object): def init(self, a): super(A, self).init(a) self.a = a print "A"
class B(object): def init(self, a): #super(B, self).init(a) self.b = a print "B"
class C(A, B): def init(self, a): super(C, self).init(a) self.c = a print "C", dir(self)
C(1)
which is really ugly (as in, why is B's call to super.init commented but not A's, if A and B are otherwise identical?)
I'm not sure, but I think the proper behavior for object.init should be ignoring all args.
- Alexandre
- Previous message: [Python-Dev] py3k: TypeError: object.__init__() takes no parameters
- Next message: [Python-Dev] py3k: TypeError: object.__init__() takes no parameters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]