@@ -205,7 +205,7 @@ impl PyString {
205205 }
206206 #[ pymethod( name = "__add__" ) ]
207207 fn add ( & self , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult < String > {
208- if objtype:: isinstance ( & rhs, & vm. ctx . str_type ( ) ) {
208+ if objtype:: isinstance ( & rhs, & vm. ctx . types . str_type ) {
209209 Ok ( format ! ( "{}{}" , self . value, borrow_value( & rhs) ) )
210210 } else {
211211 Err ( vm. new_type_error ( format ! ( "Cannot add {} and {}" , self , rhs) ) )
@@ -219,7 +219,7 @@ impl PyString {
219219
220220 #[ pymethod( name = "__eq__" ) ]
221221 fn eq ( & self , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
222- if objtype:: isinstance ( & rhs, & vm. ctx . str_type ( ) ) {
222+ if objtype:: isinstance ( & rhs, & vm. ctx . types . str_type ) {
223223 vm. new_bool ( self . value == borrow_value ( & rhs) )
224224 } else {
225225 vm. ctx . not_implemented ( )
@@ -228,7 +228,7 @@ impl PyString {
228228
229229 #[ pymethod( name = "__ne__" ) ]
230230 fn ne ( & self , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyObjectRef {
231- if objtype:: isinstance ( & rhs, & vm. ctx . str_type ( ) ) {
231+ if objtype:: isinstance ( & rhs, & vm. ctx . types . str_type ) {
232232 vm. new_bool ( self . value != borrow_value ( & rhs) )
233233 } else {
234234 vm. ctx . not_implemented ( )
@@ -609,7 +609,7 @@ impl PyString {
609609 }
610610
611611 let zelf = & args. args [ 0 ] ;
612- if !objtype:: isinstance ( & zelf, & vm. ctx . str_type ( ) ) {
612+ if !objtype:: isinstance ( & zelf, & vm. ctx . types . str_type ) {
613613 let zelf_typ = zelf. class ( ) ;
614614 let actual_type = vm. to_pystr ( & zelf_typ) ?;
615615 return Err ( vm. new_type_error ( format ! (
@@ -1287,7 +1287,7 @@ fn call_object_format(vm: &VirtualMachine, argument: PyObjectRef, format_spec: &
12871287 let returned_type = vm. ctx . new_str ( new_format_spec. to_owned ( ) ) ;
12881288
12891289 let result = vm. call_method ( & argument, "__format__" , vec ! [ returned_type] ) ?;
1290- if !objtype:: isinstance ( & result, & vm. ctx . str_type ( ) ) {
1290+ if !objtype:: isinstance ( & result, & vm. ctx . types . str_type ) {
12911291 let result_type = result. class ( ) ;
12921292 let actual_type = vm. to_pystr ( & result_type) ?;
12931293 return Err ( vm. new_type_error ( format ! ( "__format__ must return a str, not {}" , actual_type) ) ) ;
@@ -1315,7 +1315,7 @@ fn do_cformat_specifier(
13151315 Ok ( format_spec. format_string ( clone_value ( & result) ) )
13161316 }
13171317 CFormatType :: Number ( _) => {
1318- if !objtype:: isinstance ( & obj, & vm. ctx . int_type ( ) ) {
1318+ if !objtype:: isinstance ( & obj, & vm. ctx . types . int_type ) {
13191319 let required_type_string = match format_type {
13201320 CFormatType :: Number ( Decimal ) => "a number" ,
13211321 CFormatType :: Number ( _) => "an integer" ,
@@ -1330,9 +1330,9 @@ fn do_cformat_specifier(
13301330 }
13311331 Ok ( format_spec. format_number ( objint:: get_value ( & obj) ) )
13321332 }
1333- CFormatType :: Float ( _) => if objtype:: isinstance ( & obj, & vm. ctx . float_type ( ) ) {
1333+ CFormatType :: Float ( _) => if objtype:: isinstance ( & obj, & vm. ctx . types . float_type ) {
13341334 format_spec. format_float ( objfloat:: get_value ( & obj) )
1335- } else if objtype:: isinstance ( & obj, & vm. ctx . int_type ( ) ) {
1335+ } else if objtype:: isinstance ( & obj, & vm. ctx . types . int_type ) {
13361336 format_spec. format_float ( objint:: get_value ( & obj) . to_f64 ( ) . unwrap ( ) )
13371337 } else {
13381338 let required_type_string = "an floating point or integer" ;
@@ -1346,15 +1346,15 @@ fn do_cformat_specifier(
13461346 . map_err ( |e| vm. new_not_implemented_error ( e) ) ,
13471347 CFormatType :: Character => {
13481348 let char_string = {
1349- if objtype:: isinstance ( & obj, & vm. ctx . int_type ( ) ) {
1349+ if objtype:: isinstance ( & obj, & vm. ctx . types . int_type ) {
13501350 // BigInt truncation is fine in this case because only the unicode range is relevant
13511351 match objint:: get_value ( & obj) . to_u32 ( ) . and_then ( char:: from_u32) {
13521352 Some ( value) => Ok ( value. to_string ( ) ) ,
13531353 None => {
13541354 Err ( vm. new_overflow_error ( "%c arg not in range(0x110000)" . to_owned ( ) ) )
13551355 }
13561356 }
1357- } else if objtype:: isinstance ( & obj, & vm. ctx . str_type ( ) ) {
1357+ } else if objtype:: isinstance ( & obj, & vm. ctx . types . str_type ) {
13581358 let s = borrow_value ( & obj) ;
13591359 let num_chars = s. chars ( ) . count ( ) ;
13601360 if num_chars != 1 {
@@ -1384,7 +1384,7 @@ fn try_update_quantity_from_tuple(
13841384 match elements. next ( ) {
13851385 Some ( width_obj) => {
13861386 tuple_index += 1 ;
1387- if !objtype:: isinstance ( & width_obj, & vm. ctx . int_type ( ) ) {
1387+ if !objtype:: isinstance ( & width_obj, & vm. ctx . types . int_type ) {
13881388 Err ( vm. new_type_error ( "* wants int" . to_owned ( ) ) )
13891389 } else {
13901390 // TODO: handle errors when truncating BigInt to usize
@@ -1423,7 +1423,7 @@ pub fn do_cformat_string(
14231423 . all ( |( _, part) | CFormatPart :: has_key ( part) ) ;
14241424
14251425 let values = if mapping_required {
1426- if !objtype:: isinstance ( & values_obj, & vm. ctx . dict_type ( ) ) {
1426+ if !objtype:: isinstance ( & values_obj, & vm. ctx . types . dict_type ) {
14271427 return Err ( vm. new_type_error ( "format requires a mapping" . to_owned ( ) ) ) ;
14281428 }
14291429 values_obj. clone ( )
@@ -1440,7 +1440,7 @@ pub fn do_cformat_string(
14401440 }
14411441
14421442 // convert `values_obj` to a new tuple if it's not a tuple
1443- if !objtype:: isinstance ( & values_obj, & vm. ctx . tuple_type ( ) ) {
1443+ if !objtype:: isinstance ( & values_obj, & vm. ctx . types . tuple_type ) {
14441444 vm. ctx . new_tuple ( vec ! [ values_obj. clone( ) ] )
14451445 } else {
14461446 values_obj. clone ( )
0 commit comments