@@ -908,16 +908,13 @@ internal static int ToInt32(BorrowedReference value)
908908 }
909909
910910 /// <summary>
911- /// Determines whether a Python value is a floating-point number: a Python
912- /// float (including subclasses such as numpy.float64) or a number that
913- /// defines a float conversion but no lossless integer conversion
914- /// (__float__ without __index__, e.g. numpy.float32). Integer values,
915- /// including bools and types with __index__ such as numpy.int64, are not
916- /// float-like.
911+ /// True for Python floats (including subclasses like numpy.float64) and for
912+ /// numbers with __float__ but no __index__ (like numpy.float32); __index__
913+ /// marks a type as losslessly int-convertible, so those are not float-like.
917914 /// </summary>
918915 private static bool IsFloatLike ( BorrowedReference value )
919916 {
920- // The common case for integer parameters is an actual int; exit fast.
917+ // fast path for the common case: actual ints
921918 if ( Runtime . PyInt_Check ( value ) || Runtime . PyBool_Check ( value ) )
922919 {
923920 return false ;
@@ -943,20 +940,14 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec
943940
944941 TypeCode tc = Type . GetTypeCode ( obType ) ;
945942
946- // A float-like value with a fractional part must not be silently truncated
947- // into an integer parameter. Integral-valued ones (e.g. 5.0) are still
948- // accepted. Besides Python floats this covers float subclasses such as
949- // numpy.float64 and __float__-only numbers such as numpy.float32, which
950- // would otherwise be truncated below through PyNumber_Long/__int__.
951- // This keeps single- and multi-overload binding consistent: MethodBinder
952- // only treats integral floats as candidates for integer parameters, and
953- // this guard enforces the same rule at conversion time.
943+ // Reject non-integral float-like values (incl. numpy floats) for integer
944+ // targets; the PyNumber_Long path below would silently truncate them.
954945 if ( tc . IsInteger ( ) && IsFloatLike ( value ) )
955946 {
956947 double dbl = Runtime . PyFloat_AsDouble ( value ) ;
957948 if ( dbl == - 1.0 && Exceptions . ErrorOccurred ( ) )
958949 {
959- // __float__ itself failed; don't let the probe error leak
950+ // don't let a failed __float__ probe leak
960951 Exceptions . Clear ( ) ;
961952 goto type_error ;
962953 }
0 commit comments