@@ -81,7 +81,7 @@ mod _io {
8181 use crate :: builtins:: memory:: PyMemoryView ;
8282 use crate :: builtins:: {
8383 bytes:: { PyBytes , PyBytesRef } ,
84- pybool , pytype, PyByteArray , PyStr , PyStrRef , PyTypeRef ,
84+ pytype, PyByteArray , PyStr , PyStrRef , PyTypeRef ,
8585 } ;
8686 use crate :: byteslike:: { ArgBytesLike , ArgMemoryBuffer } ;
8787 use crate :: common:: borrow:: { BorrowedValue , BorrowedValueMut } ;
@@ -113,7 +113,10 @@ mod _io {
113113 }
114114
115115 fn ensure_unclosed ( file : & PyObjectRef , msg : & str , vm : & VirtualMachine ) -> PyResult < ( ) > {
116- if pybool:: boolval ( vm, vm. get_attribute ( file. clone ( ) , "closed" ) ?) ? {
116+ if vm
117+ . get_attribute ( file. clone ( ) , "closed" ) ?
118+ . try_into_bool ( vm) ?
119+ {
117120 Err ( vm. new_value_error ( msg. to_owned ( ) ) )
118121 } else {
119122 Ok ( ( ) )
@@ -288,7 +291,7 @@ mod _io {
288291 }
289292
290293 fn file_closed ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < bool > {
291- pybool :: boolval ( vm , vm . get_attribute ( file. clone ( ) , "closed" ) ?)
294+ vm . get_attribute ( file. clone ( ) , "closed" ) ?. try_into_bool ( vm )
292295 }
293296 fn check_closed ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
294297 if file_closed ( file, vm) ? {
@@ -299,7 +302,7 @@ mod _io {
299302 }
300303
301304 fn check_readable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
302- if pybool :: boolval ( vm , vm . call_method ( file, "readable" , ( ) ) ?) ? {
305+ if vm . call_method ( file, "readable" , ( ) ) ?. try_into_bool ( vm ) ? {
303306 Ok ( ( ) )
304307 } else {
305308 Err ( new_unsupported_operation (
@@ -310,7 +313,7 @@ mod _io {
310313 }
311314
312315 fn check_writable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
313- if pybool :: boolval ( vm , vm . call_method ( file, "writable" , ( ) ) ?) ? {
316+ if vm . call_method ( file, "writable" , ( ) ) ?. try_into_bool ( vm ) ? {
314317 Ok ( ( ) )
315318 } else {
316319 Err ( new_unsupported_operation (
@@ -321,7 +324,7 @@ mod _io {
321324 }
322325
323326 fn check_seekable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
324- if pybool :: boolval ( vm , vm . call_method ( file, "seekable" , ( ) ) ?) ? {
327+ if vm . call_method ( file, "seekable" , ( ) ) ?. try_into_bool ( vm ) ? {
325328 Ok ( ( ) )
326329 } else {
327330 Err ( new_unsupported_operation (
@@ -520,7 +523,7 @@ mod _io {
520523 #[ pyslot]
521524 fn tp_iternext ( instance : & PyObjectRef , vm : & VirtualMachine ) -> PyResult {
522525 let line = vm. call_method ( instance, "readline" , ( ) ) ?;
523- if !pybool :: boolval ( vm , line. clone ( ) ) ? {
526+ if !line. clone ( ) . try_into_bool ( vm ) ? {
524527 Err ( vm. new_stop_iteration ( ) )
525528 } else {
526529 Ok ( line)
@@ -1812,7 +1815,7 @@ mod _io {
18121815 fn isatty ( & self , vm : & VirtualMachine ) -> PyResult {
18131816 // read.isatty() or write.isatty()
18141817 let res = self . read . isatty ( vm) ?;
1815- if pybool :: boolval ( vm , res. clone ( ) ) ? {
1818+ if res. clone ( ) . try_into_bool ( vm ) ? {
18161819 Ok ( res)
18171820 } else {
18181821 self . write . isatty ( vm)
@@ -2208,11 +2211,11 @@ mod _io {
22082211 let buffer = args. buffer ;
22092212
22102213 let has_read1 = vm. get_attribute_opt ( buffer. clone ( ) , "read1" ) ?. is_some ( ) ;
2211- let seekable = pybool :: boolval ( vm , vm . call_method ( & buffer, "seekable" , ( ) ) ?) ?;
2214+ let seekable = vm . call_method ( & buffer, "seekable" , ( ) ) ?. try_into_bool ( vm ) ?;
22122215
22132216 let codec = vm. state . codec_registry . lookup ( encoding. as_str ( ) , vm) ?;
22142217
2215- let encoder = if pybool :: boolval ( vm , vm . call_method ( & buffer, "writable" , ( ) ) ?) ? {
2218+ let encoder = if vm . call_method ( & buffer, "writable" , ( ) ) ?. try_into_bool ( vm ) ? {
22162219 let incremental_encoder =
22172220 codec. get_incremental_encoder ( Some ( errors. clone ( ) ) , vm) ?;
22182221 let encoding_name = vm. get_attribute_opt ( incremental_encoder. clone ( ) , "name" ) ?;
@@ -2228,7 +2231,7 @@ mod _io {
22282231 None
22292232 } ;
22302233
2231- let decoder = if pybool :: boolval ( vm , vm . call_method ( & buffer, "readable" , ( ) ) ?) ? {
2234+ let decoder = if vm . call_method ( & buffer, "readable" , ( ) ) ?. try_into_bool ( vm ) ? {
22322235 let incremental_decoder =
22332236 codec. get_incremental_decoder ( Some ( errors. clone ( ) ) , vm) ?;
22342237 // TODO: wrap in IncrementalNewlineDecoder if newlines == Universal | Passthrough
0 commit comments