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

Commit8f258ac

Browse files
authored
Merge pull request#377 from vmuriart/method_object
Method overload object type
2 parents909b7c0 +4071aa3 commit8f258ac

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

‎src/runtime/methodbinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
375375
if(clrtype!=null)
376376
{
377377
vartypematch=false;
378-
if(pi[n].ParameterType!=clrtype)
378+
if((pi[n].ParameterType!=typeof(object))&&(pi[n].ParameterType!=clrtype))
379379
{
380380
IntPtrpytype=Converter.GetPythonTypeByAlias(pi[n].ParameterType);
381381
pyoptype=Runtime.PyObject_Type(op);

‎src/testing/methodtest.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,71 @@ public static int[] TestOverloadedParams(int v, int[] args)
116116
returnargs;
117117
}
118118

119+
publicstaticstringTestOverloadedNoObject(inti)
120+
{
121+
return"Got int";
122+
}
123+
124+
publicstaticstringTestOverloadedObject(inti)
125+
{
126+
return"Got int";
127+
}
128+
129+
publicstaticstringTestOverloadedObject(objecto)
130+
{
131+
return"Got object";
132+
}
133+
134+
publicstaticstringTestOverloadedObjectTwo(inta,intb)
135+
{
136+
return"Got int-int";
137+
}
138+
139+
publicstaticstringTestOverloadedObjectTwo(stringa,stringb)
140+
{
141+
return"Got string-string";
142+
}
143+
144+
publicstaticstringTestOverloadedObjectTwo(stringa,intb)
145+
{
146+
return"Got string-int";
147+
}
148+
149+
publicstaticstringTestOverloadedObjectTwo(stringa,objectb)
150+
{
151+
return"Got string-object";
152+
}
153+
154+
publicstaticstringTestOverloadedObjectTwo(inta,objectb)
155+
{
156+
return"Got int-object";
157+
}
158+
159+
publicstaticstringTestOverloadedObjectTwo(objecta,intb)
160+
{
161+
return"Got object-int";
162+
}
163+
164+
publicstaticstringTestOverloadedObjectTwo(objecta,objectb)
165+
{
166+
return"Got object-object";
167+
}
168+
169+
publicstaticstringTestOverloadedObjectTwo(inta,stringb)
170+
{
171+
return"Got int-string";
172+
}
173+
174+
publicstaticstringTestOverloadedObjectThree(objecta,intb)
175+
{
176+
return"Got object-int";
177+
}
178+
179+
publicstaticstringTestOverloadedObjectThree(inta,objectb)
180+
{
181+
return"Got int-object";
182+
}
183+
119184
publicstaticboolTestStringOutParams(strings,outstrings1)
120185
{
121186
s1="output string";

‎src/tests/test_method.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,53 @@ def test_wrong_overload():
769769
res=System.Math.Max(System.Double(50.5),50.1)
770770
assertres==50.5
771771
asserttype(res)==float
772+
773+
774+
deftest_no_object_in_param():
775+
"""Test that fix for #203 doesn't break behavior w/ no object overload"""
776+
777+
res=MethodTest.TestOverloadedNoObject(5)
778+
assertres=="Got int"
779+
780+
withpytest.raises(TypeError):
781+
MethodTest.TestOverloadedNoObject("test")
782+
783+
784+
deftest_object_in_param():
785+
"""Test regression introduced by #151 in which Object method overloads
786+
aren't being used. See #203 for issue."""
787+
788+
res=MethodTest.TestOverloadedObject(5)
789+
assertres=="Got int"
790+
791+
res=MethodTest.TestOverloadedObject("test")
792+
assertres=="Got object"
793+
794+
795+
deftest_object_in_multiparam():
796+
"""Test method with object multiparams behaves"""
797+
798+
res=MethodTest.TestOverloadedObjectTwo(5,5)
799+
assertres=="Got int-int"
800+
801+
res=MethodTest.TestOverloadedObjectTwo(5,"foo")
802+
assertres=="Got int-string"
803+
804+
res=MethodTest.TestOverloadedObjectTwo("foo",7.24)
805+
assertres=="Got string-object"
806+
807+
res=MethodTest.TestOverloadedObjectTwo("foo","bar")
808+
assertres=="Got string-string"
809+
810+
res=MethodTest.TestOverloadedObjectTwo("foo",5)
811+
assertres=="Got string-int"
812+
813+
res=MethodTest.TestOverloadedObjectTwo(7.24,7.24)
814+
assertres=="Got object-object"
815+
816+
817+
deftest_object_in_multiparam_exception():
818+
"""Test method with object multiparams behaves"""
819+
820+
withpytest.raises(TypeError):
821+
MethodTest.TestOverloadedObjectThree("foo","bar")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp