Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Revert "Wrap returned objects in interface if method return type is i…#2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
koubaa wants to merge1 commit intopythonnet:masterfromansys:return-concrete-type
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletionssrc/runtime/Converter.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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);
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/MethodBinder.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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++;
}
Expand Down
17 changes: 3 additions & 14 deletionssrc/testing/subclasstest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletionstests/test_array.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")
Expand Down
7 changes: 3 additions & 4 deletionstests/test_generic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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():
Expand DownExpand Up@@ -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)])
Expand DownExpand Up@@ -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


Expand Down
12 changes: 7 additions & 5 deletionstests/test_interface.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,12 +72,12 @@ def test_explicit_cast_to_interface():


def test_interface_object_returned_through_method():
"""Testinterface type is used if method return type is interface"""
"""Testconcrete 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'
Expand All@@ -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'

Expand DownExpand Up@@ -118,12 +118,12 @@ def test_null_interface_object_returned():
assert hello2 is None

def test_interface_array_returned():
"""Testinterface type used for methods returning interface arrays"""
"""Testconcrete 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():
Expand DownExpand Up@@ -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
9 changes: 3 additions & 6 deletionstests/test_method.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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](
Expand DownExpand Up@@ -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():
Expand Down
12 changes: 5 additions & 7 deletionstests/test_subclass.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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():
Expand DownExpand Up@@ -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():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp