views:

65

answers:

1

So, the situation is I have a C# generic class named Foo with a template parameter T which has the new() constraint. I've declared my classes something like this:

class Baz
{
    public Baz() { }
}

class Foo<T>
    where T : Baz, new()
{
    // blah blah
}

And in Python:

class Bar(Baz):
    def __init__(self):
        """ do various things here """

However, if, in Python, I try to do Foo[Bar], I get an error telling me that my Bar class violates the constraints (namely the new() constraint) on Foo<T>.

What gives?

+1  A: 

There's no default constructor for IronPython objects. They need to carry some additional mutable state with them, the Python type, which must be provided when the class is instantiated. That type is used to resolve any virtual overloads and other methods when called dynamically.

Dino Viehland
Ah yes, I figured as such when my I realized that templates were actually discarding all my Python type information. Thanks for confirming this.
rfw