1
votes

I wan't to implement the following C#/.Net interface with IronPython:

public static class Consumes<TMessage> where TMessage : class
{
   public interface All
   {
       void Consume(TMessage message);
   }
}

This is the python code I tried so far:

class TestMessage(object):
     pass

class TestConsumer(Consumes[TestMessage].All):
     def Consume(self, message):
         pass

From this I get the following exception:

TypeError: TestConsumer: cannot inhert from open generic instantiation MassTransit.Consumes`1+All[TMessage]. Only closed instantiations are supported.

A valid C# class definition to implement this interface looks following:

public class TestConsumer : Consumes<TestMessage>.All
{
    public void Consume(TestMessage msg) { }
}

So is it not possible to implement this kind of in IronPython? Or am I doing wrong?

Thank you in advance!

1
Could you either provide IConsumer or remove it from your sample. I don't expect it to be relevant but who knows. - Simon Opelt
Removed it. It is just an empty marker-interface used internally by Masstransit. Thank you for your hint! - Joachim Rosskopf

1 Answers

0
votes

It looks like implementing the nested interface as

class TestConsumer(Consumes[TestMessage].All):

does not correctly bind the type parameter TMessage even though that would be expected from the syntax. If the type is provided at the end ("for the interface instead of the surrounding class") it seems to work as expected:

class TestConsumer(Consumes.All[TestMessage]):

What would also work is importing the interface All explicitly and use it looking like a standalone generic interface:

from MyLib.Consumes import All
class TestConsumer(All[TestMessage]):

It does not seem obvious if this behavior is correct/defined that way or if there is a bug in the type generation (besides from the "inhert"-typo) or in the way the generic parameters are defined/bound. It looks to be also accepted to bind the parameter twice:

class PyTestConsumer(Consumes[String].All[String]):

even with different values which does not make much sense looking at it from a .NET perspective:

class PyTestConsumer(Consumes[List[String]].All[String]):