@@ -431,10 +431,6 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
431431
432432 internal Binding Bind ( BorrowedReference inst , BorrowedReference args , BorrowedReference kw , MethodBase info )
433433 {
434- // Relevant function variables used post conversion
435- Binding bindingUsingImplicitConversion = null ;
436- Binding genericBinding = null ;
437-
438434 // If we have KWArgs create dictionary and collect them
439435 Dictionary < string , PyObject > kwArgDict = null ;
440436 if ( kw != null )
@@ -456,8 +452,8 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
456452 var methods = info == null ? GetMethods ( )
457453 : new List < MethodInformation > ( 1 ) { new MethodInformation ( info , true ) } ;
458454
459- var matches = new List < MatchedMethod > ( ) ;
460- var matchesUsingImplicitConversion = new List < MatchedMethod > ( ) ;
455+ var matches = new List < MatchedMethod > ( methods . Count ) ;
456+ List < MatchedMethod > matchesUsingImplicitConversion = null ;
461457
462458 for ( var i = 0 ; i < methods . Count ; i ++ )
463459 {
@@ -517,11 +513,11 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
517513 var parameter = pi [ paramIndex ] ; // Clr parameter we are targeting
518514 object arg ; // Python -> Clr argument
519515
520- var hasNamedParam = kwArgDict == null ? false : kwArgDict . TryGetValue ( paramNames [ paramIndex ] , out tempPyObject ) ;
521-
522516 // Check positional arguments first and then check for named arguments and optional values
523517 if ( paramIndex >= pyArgCount )
524518 {
519+ var hasNamedParam = kwArgDict == null ? false : kwArgDict . TryGetValue ( paramNames [ paramIndex ] , out tempPyObject ) ;
520+
525521 // All positional arguments have been used:
526522 // Check our KWargs for this parameter
527523 if ( hasNamedParam )
@@ -698,18 +694,26 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe
698694 }
699695
700696 var match = new MatchedMethod ( kwargsMatched , margs , outs , mi ) ;
701- if ( usedImplicitConversion )
697+ // Only add matches using implicit conversion if no other regular matches were found,
698+ // since we favor regular matches over matches using implicit conversion
699+ if ( usedImplicitConversion && matches . Count == 0 )
702700 {
701+ if ( matchesUsingImplicitConversion == null )
702+ {
703+ matchesUsingImplicitConversion = new List < MatchedMethod > ( ) ;
704+ }
703705 matchesUsingImplicitConversion . Add ( match ) ;
704706 }
705707 else
706708 {
707709 matches . Add ( match ) ;
710+ // We don't need the matches using implicit conversion anymore
711+ matchesUsingImplicitConversion = null ;
708712 }
709713 }
710714 }
711715
712- if ( matches . Count > 0 || matchesUsingImplicitConversion . Count > 0 )
716+ if ( matches . Count > 0 || ( matchesUsingImplicitConversion != null && matchesUsingImplicitConversion . Count > 0 ) )
713717 {
714718 // We favor matches that do not use implicit conversion
715719 var matchesTouse = matches . Count > 0 ? matches : matchesUsingImplicitConversion ;
0 commit comments