diff --git a/src/runtime/Converter.cs b/src/runtime/Converter.cs index 73bbd4a3a..d5052682b 100644 --- a/src/runtime/Converter.cs +++ b/src/runtime/Converter.cs @@ -138,12 +138,6 @@ internal static NewReference ToPython(object? value, Type type) } } - if (type.IsInterface) - { - var ifaceObj = (InterfaceObject)ClassManager.GetClassImpl(type); - return ifaceObj.TryWrapObject(value); - } - if (type.IsArray || type.IsEnum) { return CLRObject.GetReference(value, type); diff --git a/src/runtime/MethodBinder.cs b/src/runtime/MethodBinder.cs index 07ed4fe22..205c35f49 100644 --- a/src/runtime/MethodBinder.cs +++ b/src/runtime/MethodBinder.cs @@ -945,7 +945,7 @@ internal virtual NewReference Invoke(BorrowedReference inst, BorrowedReference a Type pt = pi[i].ParameterType; if (pt.IsByRef) { - using var v = Converter.ToPython(binding.args[i], pt.GetElementType()); + using var v = Converter.ToPython(binding.args[i], pt); Runtime.PyTuple_SetItem(t.Borrow(), n, v.Steal()); n++; } diff --git a/src/testing/subclasstest.cs b/src/testing/subclasstest.cs index ab0b73368..9817d865e 100644 --- a/src/testing/subclasstest.cs +++ b/src/testing/subclasstest.cs @@ -89,24 +89,13 @@ public static string test_bar(IInterfaceTest x, string s, int i) } // test instances can be constructed in managed code - public static SubClassTest create_instance(Type t) - { - return (SubClassTest)t.GetConstructor(new Type[] { }).Invoke(new object[] { }); - } - - public static IInterfaceTest create_instance_interface(Type t) + public static IInterfaceTest create_instance(Type t) { return (IInterfaceTest)t.GetConstructor(new Type[] { }).Invoke(new object[] { }); } - // test instances pass through managed code unchanged ... - public static SubClassTest pass_through(SubClassTest s) - { - return s; - } - - // ... but the return type is an interface type, objects get wrapped - public static IInterfaceTest pass_through_interface(IInterfaceTest s) + // test instances pass through managed code unchanged + public static IInterfaceTest pass_through(IInterfaceTest s) { return s; } diff --git a/tests/test_array.py b/tests/test_array.py index d207a36fb..80c60383f 100644 --- a/tests/test_array.py +++ b/tests/test_array.py @@ -1335,10 +1335,9 @@ def test_special_array_creation(): assert value[1].__class__ == inst.__class__ assert value.Length == 2 - iface_class = ISayHello1(inst).__class__ value = Array[ISayHello1]([inst, inst]) - assert value[0].__class__ == iface_class - assert value[1].__class__ == iface_class + assert value[0].__class__ == inst.__class__ + assert value[1].__class__ == inst.__class__ assert value.Length == 2 inst = System.Exception("badness") diff --git a/tests/test_generic.py b/tests/test_generic.py index 6d514d638..6364878b8 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -330,6 +330,7 @@ def test_generic_method_type_handling(): assert_generic_method_by_type(ShortEnum, ShortEnum.Zero) assert_generic_method_by_type(System.Object, InterfaceTest()) assert_generic_method_by_type(InterfaceTest, InterfaceTest(), 1) + assert_generic_method_by_type(ISayHello1, InterfaceTest(), 1) def test_correct_overload_selection(): @@ -558,11 +559,10 @@ def test_method_overload_selection_with_generic_types(): value = MethodTest.Overloaded.__overloads__[vtype](input_) assert value.value.__class__ == inst.__class__ - iface_class = ISayHello1(inst).__class__ vtype = GenericWrapper[ISayHello1] input_ = vtype(inst) value = MethodTest.Overloaded.__overloads__[vtype](input_) - assert value.value.__class__ == iface_class + assert value.value.__class__ == inst.__class__ vtype = System.Array[GenericWrapper[int]] input_ = vtype([GenericWrapper[int](0), GenericWrapper[int](1)]) @@ -737,12 +737,11 @@ def test_overload_selection_with_arrays_of_generic_types(): assert value[0].value.__class__ == inst.__class__ assert value.Length == 2 - iface_class = ISayHello1(inst).__class__ gtype = GenericWrapper[ISayHello1] vtype = System.Array[gtype] input_ = vtype([gtype(inst), gtype(inst)]) value = MethodTest.Overloaded.__overloads__[vtype](input_) - assert value[0].value.__class__ == iface_class + assert value[0].value.__class__ == inst.__class__ assert value.Length == 2 diff --git a/tests/test_interface.py b/tests/test_interface.py index ac620684d..182b6b112 100644 --- a/tests/test_interface.py +++ b/tests/test_interface.py @@ -72,12 +72,12 @@ def test_explicit_cast_to_interface(): def test_interface_object_returned_through_method(): - """Test interface type is used if method return type is interface""" + """Test concrete type is used if method return type is interface""" from Python.Test import InterfaceTest ob = InterfaceTest() hello1 = ob.GetISayHello1() - assert type(hello1).__name__ == 'ISayHello1' + assert type(hello1).__name__ == 'InterfaceTest' assert hello1.__implementation__.__class__.__name__ == "InterfaceTest" assert hello1.SayHello() == 'hello 1' @@ -89,7 +89,7 @@ def test_interface_object_returned_through_out_param(): ob = InterfaceTest() hello2 = ob.GetISayHello2(None) - assert type(hello2).__name__ == 'ISayHello2' + assert type(hello2).__name__ == 'InterfaceTest' assert hello2.SayHello() == 'hello 2' @@ -118,12 +118,12 @@ def test_null_interface_object_returned(): assert hello2 is None def test_interface_array_returned(): - """Test interface type used for methods returning interface arrays""" + """Test concrete type used for methods returning interface arrays""" from Python.Test import InterfaceTest ob = InterfaceTest() hellos = ob.GetISayHello1Array() - assert type(hellos[0]).__name__ == 'ISayHello1' + assert type(hellos[0]).__name__ == 'InterfaceTest' assert hellos[0].__implementation__.__class__.__name__ == "InterfaceTest" def test_implementation_access(): @@ -161,3 +161,5 @@ def test_methods_of_Object_are_available(): assert clrVal.GetHashCode() == i.GetHashCode() assert clrVal.GetType() == i.GetType() assert clrVal.ToString() == i.ToString() +======= +>>>>>>> parent of 1dd36ae (Wrap returned objects in interface if method return type is interface):src/tests/test_interface.py diff --git a/tests/test_method.py b/tests/test_method.py index b86bbd6b4..eee359c1b 100644 --- a/tests/test_method.py +++ b/tests/test_method.py @@ -583,10 +583,8 @@ def test_explicit_overload_selection(): value = MethodTest.Overloaded.__overloads__[InterfaceTest](inst) assert value.__class__ == inst.__class__ - iface_class = ISayHello1(InterfaceTest()).__class__ value = MethodTest.Overloaded.__overloads__[ISayHello1](inst) - assert value.__class__ != inst.__class__ - assert value.__class__ == iface_class + assert value.__class__ == inst.__class__ atype = Array[System.Object] value = MethodTest.Overloaded.__overloads__[str, int, atype]( @@ -739,12 +737,11 @@ def test_overload_selection_with_array_types(): assert value[0].__class__ == inst.__class__ assert value[1].__class__ == inst.__class__ - iface_class = ISayHello1(inst).__class__ vtype = Array[ISayHello1] input_ = vtype([inst, inst]) value = MethodTest.Overloaded.__overloads__[vtype](input_) - assert value[0].__class__ == iface_class - assert value[1].__class__ == iface_class + assert value[0].__class__ == inst.__class__ + assert value[1].__class__ == inst.__class__ def test_explicit_overload_selection_failure(): diff --git a/tests/test_subclass.py b/tests/test_subclass.py index 504b82548..015c52613 100644 --- a/tests/test_subclass.py +++ b/tests/test_subclass.py @@ -123,10 +123,8 @@ def test_interface(): assert ob.bar("bar", 2) == "bar/bar" assert FunctionsTest.test_bar(ob, "bar", 2) == "bar/bar" - # pass_through will convert from InterfaceTestClass -> IInterfaceTest, - # causing a new wrapper object to be created. Hence id will differ. - x = FunctionsTest.pass_through_interface(ob) - assert id(x) != id(ob) + x = FunctionsTest.pass_through(ob) + assert id(x) == id(ob) def test_derived_class(): @@ -199,14 +197,14 @@ def test_create_instance(): assert id(x) == id(ob) InterfaceTestClass = interface_test_class_fixture(test_create_instance.__name__) - ob2 = FunctionsTest.create_instance_interface(InterfaceTestClass) + ob2 = FunctionsTest.create_instance(InterfaceTestClass) assert ob2.foo() == "InterfaceTestClass" assert FunctionsTest.test_foo(ob2) == "InterfaceTestClass" assert ob2.bar("bar", 2) == "bar/bar" assert FunctionsTest.test_bar(ob2, "bar", 2) == "bar/bar" - y = FunctionsTest.pass_through_interface(ob2) - assert id(y) != id(ob2) + y = FunctionsTest.pass_through(ob2) + assert id(y) == id(ob2) def test_events():