- Notifications
You must be signed in to change notification settings - Fork749
Closed
Labels
Description
Environment
- Pythonnet version: 2.5.2 and 3.0.0.post01
- Python version: 3.7.6 (2.5.2) and 3.9.12 (3.0.0.post01)
- Operating System: Win10
- .NET Runtime: .NET 6
Details
Passing a Python object (obj
) that implements a generic interface in Python (ISome
) to a C# classfails in pythonnet 3.0 butworks in 2.5.2; same behaviour whether specific (SomeSpecific
) or generic (SomeGeneric
)
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
namespaceSome.Namespace{publicinterfaceISome<T1>{publicT1Get1(T1x);}publicclassSomeSpecific{publicSomeSpecific(ISome<int>some,intx){Console.Out.WriteLine($"Spec1 ={some.Get1(x)}");}}publicclassSomeGeneric<T1>{publicSomeGeneric(ISome<T1>some,T1x){Console.Out.WriteLine($"Gen1 ={some.Get1(x)}");}}}
fromSome.NamespaceimportISome,SomeGeneric,SomeSpecificclassPySome(ISome[int]):__namespace__='Some.Namespace'defGet1(self,x):returnxobj=PySome()print(obj.Get1(4))# Next two lines fail in 3.0.0SomeSpecific(obj,4)SomeGeneric[int](obj,4)
- If there was a crash, please include the traceback here.
Traceback (mostrecentcalllast):SomeSpecific(obj,4)System.ArgumentException:CannotresolvemethodInt32Get1(Int32)becausethedeclaring typeofthemethodhandleSome.Namespace.ISome`1[T1]isgeneric.Explicitlyprovidethedeclaring typetoGetMethodFromHandle.atSystem.Reflection.MethodBase.GetMethodFromHandle(RuntimeMethodHandlehandle)atPython.Runtime.PythonDerivedType.MarshalByRefsBack(Object[]args,RuntimeMethodHandlemethodHandle,PyObjectpyResult,Int32outsOffset)in/tmp/build-via-sdist-rlpexh5w/pythonnet-3.0.0.post1/src/runtime/Types/ClassDerived.cs:line844atPython.Runtime.PythonDerivedType.InvokeMethod[T](IPythonDerivedTypeobj,StringmethodName,StringorigMethodName,Object[]args,RuntimeMethodHandlemethodHandle)in/tmp/build-via-sdist-rlpexh5w/pythonnet-3.0.0.post1/src/runtime/Types/ClassDerived.cs:line727atSome.Namespace.PySome.Get1(Int32 )atSome.Namespace.SomeSpecific..ctor(ISome`1some,Int32x)in