@@ -957,8 +957,9 @@ Object floatFromLong(Object cls, long arg) {
957
957
return factory ().createFloat (cls , arg );
958
958
}
959
959
960
- @ Specialization (guards = "!isNativeClass(cls)" )
961
- Object floatFromPInt (Object cls , PInt arg ) {
960
+ @ Specialization (guards = {"!isNativeClass(cls)" , "cannotBeOverridden(plib.getLazyPythonClass(arg))" })
961
+ Object floatFromPInt (Object cls , PInt arg ,
962
+ @ CachedLibrary (limit = "1" ) @ SuppressWarnings ("unused" ) PythonObjectLibrary plib ) {
962
963
double value = arg .doubleValue ();
963
964
if (Double .isInfinite (value )) {
964
965
throw raise (OverflowError , ErrorMessages .TOO_LARGE_TO_CONVERT_TO , "int" , "float" );
@@ -1096,11 +1097,14 @@ Object floatFromNone(Object cls, @SuppressWarnings("unused") PNone arg) {
1096
1097
return factory ().createFloat (cls , 0.0 );
1097
1098
}
1098
1099
1099
- static boolean isHandledType (Object o ) {
1100
+ static boolean isHandledType (PythonObjectLibrary lib , Object o ) {
1101
+ if (o instanceof PInt ) {
1102
+ return PGuards .cannotBeOverridden (lib .getLazyPythonClass (o ));
1103
+ }
1100
1104
return PGuards .canBeInteger (o ) || PGuards .isDouble (o ) || o instanceof String || PGuards .isPNone (o );
1101
1105
}
1102
1106
1103
- @ Specialization (guards = {"isPrimitiveFloat(cls)" , "!isHandledType(obj)" })
1107
+ @ Specialization (guards = {"isPrimitiveFloat(cls)" , "!isHandledType(lib, obj)" })
1104
1108
double doubleFromObject (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object cls , Object obj ,
1105
1109
@ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ) {
1106
1110
// Follows logic from PyNumber_Float:
@@ -3181,11 +3185,6 @@ private String getStringArg(Object arg) {
3181
3185
throw raise (SystemError , ErrorMessages .BAD_ARG_TO_INTERNAL_FUNC );
3182
3186
}
3183
3187
}
3184
-
3185
- @ TruffleBoundary
3186
- private static byte [] toBytes (String data ) {
3187
- return data .getBytes ();
3188
- }
3189
3188
}
3190
3189
3191
3190
@ Builtin (name = "cell" , constructsClass = PythonBuiltinClassType .PCell , isPublic = false )
0 commit comments