@@ -704,7 +704,7 @@ struct IntOptions {
704
704
#[ pyarg( positional_only, optional = true ) ]
705
705
val_options : OptionalArg < PyObjectRef > ,
706
706
#[ pyarg( positional_or_keyword, optional = true ) ]
707
- base : OptionalArg < u32 > ,
707
+ base : OptionalArg < i32 > ,
708
708
}
709
709
710
710
impl IntOptions {
@@ -736,7 +736,7 @@ fn int_new(cls: PyClassRef, options: IntOptions, vm: &VirtualMachine) -> PyResul
736
736
}
737
737
738
738
// Casting function:
739
- pub fn to_int ( vm : & VirtualMachine , obj : & PyObjectRef , base : u32 ) -> PyResult < BigInt > {
739
+ pub fn to_int ( vm : & VirtualMachine , obj : & PyObjectRef , base : i32 ) -> PyResult < BigInt > {
740
740
if base != 0 && ( base < 2 || base > 36 ) {
741
741
return Err ( vm. new_value_error ( "int() base must be >= 2 and <= 36, or 0" . to_string ( ) ) ) ;
742
742
}
@@ -772,7 +772,7 @@ pub fn to_int(vm: &VirtualMachine, obj: &PyObjectRef, base: u32) -> PyResult<Big
772
772
} )
773
773
}
774
774
775
- fn str_to_int ( vm : & VirtualMachine , literal : & str , mut base : u32 ) -> PyResult < BigInt > {
775
+ fn str_to_int ( vm : & VirtualMachine , literal : & str , mut base : i32 ) -> PyResult < BigInt > {
776
776
let mut buf = validate_literal ( vm, literal, base) ?;
777
777
let is_signed = buf. starts_with ( '+' ) || buf. starts_with ( '-' ) ;
778
778
let radix_range = if is_signed { 1 ..3 } else { 0 ..2 } ;
@@ -800,10 +800,10 @@ fn str_to_int(vm: &VirtualMachine, literal: &str, mut base: u32) -> PyResult<Big
800
800
base = 10 ;
801
801
}
802
802
803
- BigInt :: from_str_radix ( & buf, base) . map_err ( |_err| invalid_literal ( vm, literal, base) )
803
+ BigInt :: from_str_radix ( & buf, base as u32 ) . map_err ( |_err| invalid_literal ( vm, literal, base) )
804
804
}
805
805
806
- fn validate_literal ( vm : & VirtualMachine , literal : & str , base : u32 ) -> PyResult < String > {
806
+ fn validate_literal ( vm : & VirtualMachine , literal : & str , base : i32 ) -> PyResult < String > {
807
807
if literal. starts_with ( '_' ) || literal. ends_with ( '_' ) {
808
808
return Err ( invalid_literal ( vm, literal, base) ) ;
809
809
}
@@ -826,7 +826,7 @@ fn validate_literal(vm: &VirtualMachine, literal: &str, base: u32) -> PyResult<S
826
826
Ok ( buf)
827
827
}
828
828
829
- fn detect_base ( literal : & str ) -> Option < u32 > {
829
+ fn detect_base ( literal : & str ) -> Option < i32 > {
830
830
match literal {
831
831
"0x" | "0X" => Some ( 16 ) ,
832
832
"0o" | "0O" => Some ( 8 ) ,
@@ -835,7 +835,7 @@ fn detect_base(literal: &str) -> Option<u32> {
835
835
}
836
836
}
837
837
838
- fn invalid_literal ( vm : & VirtualMachine , literal : & str , base : u32 ) -> PyObjectRef {
838
+ fn invalid_literal ( vm : & VirtualMachine , literal : & str , base : i32 ) -> PyObjectRef {
839
839
vm. new_value_error ( format ! (
840
840
"invalid literal for int() with base {}: '{}'" ,
841
841
base, literal
0 commit comments