[IronPython] __init__ ignored in favor of base class constructor? - blocker
fuzzyman at voidspace.org.uk
Sun Nov 30 14:30:13 CET 2008
Dan Eloff wrote:
> In the 2.1 branch of 43741, it seems there is trouble subclassing a
> CLR class that has protected constructors.
> # Silverlight Toolkit
> import clr
> from Microsoft.Windows.Controls.Theming import Theme
> class MyTheme(Theme):
> def __init__(self):
> raise ValueError
> TypeError: MyTheme() takes at least 2 arguments (1 given)
> In fact you can try MyTheme(1,2,3) and get the same error. You can
> also not define an __init__ on MyTheme and get the same error.
> This would lead me to suspect it's trying the whole time to call the
> protected 2 argument constructor, and is ignoring the Python __init__
> method. This is a blocker as I've not found any way around it that
> will work in silverlight.
I can't find this assembly to experiment - but when you subclass a .NET
type in IronPython you override the constructor by overriding '__new__'
and not '__init__'. Perhaps this is the cause of your problem? (If the
default constructor takes two arguments then merely supplying an
__init__ method that only takes one won't stop the default two argument
constructor being called.)
> By the way, should I should I be using the 2.0 branch rather? I expect
> 2.1 will be released long before I make my first release, so I thought
> that's probably the way to go.
> Users mailing list
> Users at lists.ironpython.com
More information about the Ironpython-users