Hi,
I have a instrument class topic, I wanted to adress with either class inheritance or mixins in Python.
What I’d like to achieve is the following.
There are instruments
- A1, A2, A3, … of parent type A
- B1, B2, B3, … of parent type B
- C1, C2, … of parent type C
with A, B, C derived from OpenTap.ScipInstrument.
Now, the implementation of C1 is a combination of A1 and B1. With that, I’d like to implement A1, B2, C3 with a shared code base rather than copying things.
I thought about implementing C1 with class inheritance from (ScpiInstrument,A1,B1) but that fails with “PythonException: Multiple inheritance with managed classes cannot be used.”
Second try was to have a Python mixins M1, M2 such that are defined as
- class M1
- class M2
- class A1 (ScpiInstrument,M1)
- class B1 (ScipiIinstrument,M2)
- class C1(ScipiInstrument,M1,M2)
throwing the PythonException: Non .NET type used as super class for meta type. This is not supported.
If M1 is derived from IResource, IInstrument it fails with PythonException: Method ‘xxxx’ in Type ‘M1’ from assembly ‘Python.Runtime.Dynamic’ does not have an implementation’ with different functions xxxx missing depending on the interface parent.
What I found is a statement in Creating Python Classes Derived from C# Class saying, there shall be no inheritance (not sure, if that applies to my scenario).
Can you give an recommendation how my instrument challenge can be addressed?
Thanks.
Best regards,
Gernot