@@ -989,11 +989,6 @@ private Object toIntInternal(Object number, Object base) {
989
989
}
990
990
}
991
991
992
- private Object toInt (LazyPythonClass cls , Object number ) {
993
- Object value = toIntInternal (number );
994
- return convertToIntInternal (cls , value , number , 10 );
995
- }
996
-
997
992
private Object toInt (LazyPythonClass cls , Object number , int base ) {
998
993
Object value = toIntInternal (number , base );
999
994
return convertToIntInternal (cls , value , number , base );
@@ -1226,13 +1221,19 @@ Object parsePIntError(LazyPythonClass cls, String number, int base) {
1226
1221
}
1227
1222
}
1228
1223
1229
- @ Specialization
1230
- public Object createInt (LazyPythonClass cls , String number , Object keywordArg ) {
1231
- if (keywordArg instanceof PNone ) {
1232
- return toInt (cls , number );
1233
- } else {
1234
- CompilerDirectives .transferToInterpreter ();
1235
- throw new RuntimeException ("Not implemented integer with base: " + keywordArg );
1224
+ @ Specialization (guards = "!isNoValue(base)" , rewriteOn = NumberFormatException .class )
1225
+ public Object parsePIntWithBaseObject (LazyPythonClass cls , String number , Object base ,
1226
+ @ Cached CastToIndexNode castToIndexNode ) {
1227
+ return toInt (cls , number , castToIndexNode .execute (base ));
1228
+ }
1229
+
1230
+ @ Specialization (guards = "!isNoValue(base)" , replaces = "parsePIntWithBaseObject" )
1231
+ public Object createIntError (LazyPythonClass cls , String number , Object base ,
1232
+ @ Cached CastToIndexNode castToIndexNode ) {
1233
+ try {
1234
+ return toInt (cls , number , castToIndexNode .execute (base ));
1235
+ } catch (NumberFormatException e ) {
1236
+ throw raise (ValueError , "invalid literal for int() with base %s: %s" , base , number );
1236
1237
}
1237
1238
}
1238
1239
0 commit comments