[IronPython] __init__ ignored in favor of base class constructor? - blocker

Dino Viehland dinov at microsoft.com
Mon Dec 1 20:43:45 CET 2008


Ok, I think the problem here is two-fold.  First there's no public default constructor - only a private one.  So you need to pick between the Stream overload or the StreamResourceInfo, Uri overload.  You're apparently trying to choose the Stream overload.

Which brings me to the 2nd problem.  Quite surprisingly GetResourceStream doesn't seem to return a stream - it returns a StreamResourceInfo.  So ultimately there are no applicable methods for us to call.

I think you want:

class MyTheme(Theme):
    def __new__(cls):
        return Theme.__new__(cls, Application.GetResourceStream(Uri('theme.xaml', UriKind.Relative)).Stream)

And then we need to continue to work on improving our error messages which remain particularly bad in some spots :).

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Sunday, November 30, 2008 7:43 AM
To: Discussion of IronPython
Subject: Re: [IronPython] __init__ ignored in favor of base class constructor? - blocker

On Sun, Nov 30, 2008 at 8:30 AM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> Hello Dan,
>
> 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.)
>

I don't think I've ever subclassed a .NET type that has a default
constructor taking an argument, hopefully the problem here is with me
and not IronPython :) I thought __new__ might be the one to use, but I
got these errors with __new__:

class MyTheme(Theme):
    def __new__(cls):
        return Theme.__new__(cls,
Application.GetResourceStream(Uri('theme.xaml', UriKind.Relative)))

TypeError: default __new__ does not take parameters.

If I use:

class MyTheme(Theme):
    def __new__(cls):
        return Theme.__new__(cls)

TypeError: MyTheme() takes at least 2 arguments (1 given)

Back to square one. Do you have some idea what I'm doing wrong here?
The assembly is from the Silverlight Toolkit:
http://www.codeplex.com/Silverlight

-Dan
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list