@@ -316,7 +316,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
316316 Runtime . XDecref ( valueList ) ;
317317 }
318318
319- var numPyArgs = ( int ) Runtime . PyTuple_Size ( args ) ;
319+ var pynargs = ( int ) Runtime . PyTuple_Size ( args ) ;
320320 var isGeneric = false ;
321321 if ( info != null )
322322 {
@@ -343,14 +343,19 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
343343 int kwargsMatched ;
344344 int defaultsNeeded ;
345345 bool isOperator = OperatorMethod . IsOperatorMethod ( mi ) ; // e.g. op_Addition is defined for OperableObject
346- if ( ! MatchesArgumentCount ( numPyArgs , pi , kwargDict , isOperator , out paramsArray , out defaultArgList , out kwargsMatched , out defaultsNeeded ) )
346+ if ( isOperator )
347+ {
348+ var a = 0 ;
349+ a ++ ;
350+ }
351+ if ( ! MatchesArgumentCount ( pynargs , pi , kwargDict , isOperator , out paramsArray , out defaultArgList , out kwargsMatched , out defaultsNeeded ) )
347352 {
348353 continue ;
349354 }
350355 var outs = 0 ;
351- int numClrArgs = pi . Length ;
352- isOperator = isOperator && numPyArgs == numClrArgs - 1 ; // Handle mismatched arg numbers due to Python operator being bound.
353- var margs = TryConvertArguments ( pi , paramsArray , args , numPyArgs , kwargDict , defaultArgList ,
356+ int clrnargs = pi . Length ;
357+ isOperator = isOperator && pynargs == clrnargs - 1 ; // Handle mismatched arg numbers due to Python operator being bound.
358+ var margs = TryConvertArguments ( pi , paramsArray , args , pynargs , kwargDict , defaultArgList ,
354359 needsResolution : _methods . Length > 1 , // If there's more than one possible match.
355360 isOperator : isOperator ,
356361 outs : out outs ) ;
@@ -669,7 +674,7 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool
669674 /// <summary>
670675 /// Check whether the number of Python and .NET arguments match, and compute additional arg information.
671676 /// </summary>
672- /// <param name="numPyArgs ">Number of positional args passed from Python.</param>
677+ /// <param name="pynargs ">Number of positional args passed from Python.</param>
673678 /// <param name="parameters">Parameters of the specified .NET method.</param>
674679 /// <param name="kwargDict">Keyword args passed from Python.</param>
675680 /// <param name="isOperator">True if the parameters' method is an operator.</param>
@@ -678,7 +683,7 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool
678683 /// <param name="kwargsMatched">Number of kwargs from Python that are also present in the .NET method.</param>
679684 /// <param name="defaultsNeeded">Number of non-null defaultsArgs.</param>
680685 /// <returns></returns>
681- static bool MatchesArgumentCount ( int numPyArgs , ParameterInfo [ ] parameters ,
686+ static bool MatchesArgumentCount ( int pynargs , ParameterInfo [ ] parameters ,
682687 Dictionary < string , IntPtr > kwargDict ,
683688 bool isOperator ,
684689 out bool paramsArray ,
@@ -688,15 +693,14 @@ static bool MatchesArgumentCount(int numPyArgs, ParameterInfo[] parameters,
688693 {
689694 defaultArgList = null ;
690695 var match = false ;
691- int numClrArgs = parameters . Length ;
692- paramsArray = numClrArgs > 0 ? Attribute . IsDefined ( parameters [ numClrArgs - 1 ] , typeof ( ParamArrayAttribute ) ) : false ;
696+ paramsArray = parameters . Length > 0 ? Attribute . IsDefined ( parameters [ parameters . Length - 1 ] , typeof ( ParamArrayAttribute ) ) : false ;
693697 kwargsMatched = 0 ;
694698 defaultsNeeded = 0 ;
695- if ( numPyArgs == numClrArgs && kwargDict . Count == 0 )
699+ if ( pynargs == parameters . Length && kwargDict . Count == 0 )
696700 {
697701 match = true ;
698702 }
699- else if ( numPyArgs < numClrArgs && ( ! paramsArray || numPyArgs == numClrArgs - 1 ) )
703+ else if ( pynargs < parameters . Length && ( ! paramsArray || pynargs == parameters . Length - 1 ) )
700704 {
701705 match = true ;
702706 // operator methods will have 2 CLR args but only one Python arg,
@@ -711,7 +715,7 @@ static bool MatchesArgumentCount(int numPyArgs, ParameterInfo[] parameters,
711715 // a corresponding keyword arg or a default param, unless the method
712716 // method accepts a params array (which cannot have a default value)
713717 defaultArgList = new ArrayList ( ) ;
714- for ( var v = numPyArgs ; v < numClrArgs ; v ++ )
718+ for ( var v = pynargs ; v < parameters . Length ; v ++ )
715719 {
716720 if ( kwargDict . ContainsKey ( parameters [ v ] . Name ) )
717721 {
@@ -736,8 +740,8 @@ static bool MatchesArgumentCount(int numPyArgs, ParameterInfo[] parameters,
736740 }
737741 }
738742 }
739- else if ( numPyArgs > numClrArgs && numClrArgs > 0 &&
740- Attribute . IsDefined ( parameters [ numClrArgs - 1 ] , typeof ( ParamArrayAttribute ) ) )
743+ else if ( pynargs > parameters . Length && parameters . Length > 0 &&
744+ Attribute . IsDefined ( parameters [ parameters . Length - 1 ] , typeof ( ParamArrayAttribute ) ) )
741745 {
742746 // This is a `foo(params object[] bar)` style method
743747 match = true ;
0 commit comments