@@ -937,7 +937,7 @@ public void Method()
937937 CalledMethodMessage = "Overload 1" ;
938938 }
939939
940- public void Method ( CSharpClass csharpClassArgument , decimal decimalArgument = 1.2m , PyObject pyObjectKArgument = null )
940+ public void Method ( CSharpClass csharpClassArgument , decimal decimalArgument = 1.2m , PyObject pyObjectKwArgument = null )
941941 {
942942 CalledMethodMessage = "Overload 2" ;
943943 }
@@ -998,6 +998,56 @@ public void PyObjectArgsHavePrecedenceOverOtherTypes()
998998 Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
999999 }
10001000
1001+ [ Test ]
1002+ public void OtherTypesHavePrecedenceOverPyObjectArgsIfMoreArgsAreMatched ( )
1003+ {
1004+ using var _ = Py . GIL ( ) ;
1005+
1006+ var instance = new CSharpClass2 ( ) ;
1007+ using var pyInstance = instance . ToPython ( ) ;
1008+ using var pyArg = new CSharpClass ( ) . ToPython ( ) ;
1009+
1010+ Assert . DoesNotThrow ( ( ) =>
1011+ {
1012+ using var kwargs = Py . kw ( "pyObjectKwArgument" , new CSharpClass2 ( ) ) ;
1013+ pyInstance . InvokeMethod ( "Method" , new [ ] { pyArg } , kwargs ) ;
1014+ } ) ;
1015+
1016+ Assert . AreEqual ( "Overload 2" , instance . CalledMethodMessage ) ;
1017+ Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
1018+ instance . Clear ( ) ;
1019+
1020+ Assert . DoesNotThrow ( ( ) =>
1021+ {
1022+ using var kwargs = Py . kw ( "py_object_kw_argument" , new CSharpClass2 ( ) ) ;
1023+ pyInstance . InvokeMethod ( "method" , new [ ] { pyArg } , kwargs ) ;
1024+ } ) ;
1025+
1026+ Assert . AreEqual ( "Overload 2" , instance . CalledMethodMessage ) ;
1027+ Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
1028+ instance . Clear ( ) ;
1029+
1030+ Assert . DoesNotThrow ( ( ) =>
1031+ {
1032+ using var kwargs = Py . kw ( "objectArgument" , "somestring" ) ;
1033+ pyInstance . InvokeMethod ( "Method" , new [ ] { pyArg } , kwargs ) ;
1034+ } ) ;
1035+
1036+ Assert . AreEqual ( "Overload 3" , instance . CalledMethodMessage ) ;
1037+ Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
1038+ instance . Clear ( ) ;
1039+
1040+ Assert . DoesNotThrow ( ( ) =>
1041+ {
1042+ using var kwargs = Py . kw ( "object_argument" , "somestring" ) ;
1043+ pyInstance . InvokeMethod ( "method" , new [ ] { pyArg } , kwargs ) ;
1044+ } ) ;
1045+
1046+ Assert . AreEqual ( "Overload 3" , instance . CalledMethodMessage ) ;
1047+ Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
1048+ instance . Clear ( ) ;
1049+ }
1050+
10011051 [ Test ]
10021052 public void BindsConstructorToSnakeCasedArgumentsVersion ( [ Values ] bool useCamelCase , [ Values ] bool passOptionalArgument )
10031053 {
0 commit comments