[IronPython] Initialisation of .NET Subclasses

Dino Viehland dinov at exchange.microsoft.com
Thu Mar 15 01:11:32 CET 2007

You are correct in that __new__ methods map to the .NET ctor (both __new__ and the ctor can only be run once, while __init__ can be called an arbitrary number of times).  Of course someone can construct a type from C# which has particular __init__ or __new__ semantics but you won't run into that in Winforms.

The only interesting thing about not calling __init__ is if multiple inheritance starts coming into the picture.  Then you might want to call your super's __init__ to ensure everyone gets __init__ run.  Unfortunately doing super(...).__init__ to make this work seems to be questionable as it may open up its own set of issues.

But there's certainly no need to Form.__init__.
From: users-bounces at lists.ironpython.com [users-bounces at lists.ironpython.com] On Behalf Of Michael Foord [fuzzyman at voidspace.org.uk]
Sent: Wednesday, March 14, 2007 4:25 PM
To: Discussion of IronPython
Subject: [IronPython] Initialisation of .NET Subclasses

Hello all,

I'm wondering about best practise when subclassing Windows Forms
controls. I have a vague memory of hearing that initialisation is done
in the '__new__' methods of .NET controls, so that '__init__' overrides
*need not* call up to their base class. Is this correct, or was I
hallucinating ?

In other words, is the following ok :

class MainForm(Form):
    def __init__(self):

Or should I be doing :

class MainForm(Form):
    def __init__(self):


All the best,

Michael Foord
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list