@@ -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,7 @@ 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 . get_attribute ( file. clone ( ) , "closed" ) ?. try_to_bool ( vm ) ? {
117117 Err ( vm. new_value_error ( msg. to_owned ( ) ) )
118118 } else {
119119 Ok ( ( ) )
@@ -288,7 +288,7 @@ mod _io {
288288 }
289289
290290 fn file_closed ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < bool > {
291- pybool :: boolval ( vm , vm . get_attribute ( file. clone ( ) , "closed" ) ?)
291+ vm . get_attribute ( file. clone ( ) , "closed" ) ?. try_to_bool ( vm )
292292 }
293293 fn check_closed ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
294294 if file_closed ( file, vm) ? {
@@ -299,7 +299,7 @@ mod _io {
299299 }
300300
301301 fn check_readable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
302- if pybool :: boolval ( vm , vm . call_method ( file, "readable" , ( ) ) ?) ? {
302+ if vm . call_method ( file, "readable" , ( ) ) ?. try_to_bool ( vm ) ? {
303303 Ok ( ( ) )
304304 } else {
305305 Err ( new_unsupported_operation (
@@ -310,7 +310,7 @@ mod _io {
310310 }
311311
312312 fn check_writable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
313- if pybool :: boolval ( vm , vm . call_method ( file, "writable" , ( ) ) ?) ? {
313+ if vm . call_method ( file, "writable" , ( ) ) ?. try_to_bool ( vm ) ? {
314314 Ok ( ( ) )
315315 } else {
316316 Err ( new_unsupported_operation (
@@ -321,7 +321,7 @@ mod _io {
321321 }
322322
323323 fn check_seekable ( file : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
324- if pybool :: boolval ( vm , vm . call_method ( file, "seekable" , ( ) ) ?) ? {
324+ if vm . call_method ( file, "seekable" , ( ) ) ?. try_to_bool ( vm ) ? {
325325 Ok ( ( ) )
326326 } else {
327327 Err ( new_unsupported_operation (
@@ -520,7 +520,7 @@ mod _io {
520520 #[ pyslot]
521521 fn tp_iternext ( instance : & PyObjectRef , vm : & VirtualMachine ) -> PyResult {
522522 let line = vm. call_method ( instance, "readline" , ( ) ) ?;
523- if !pybool :: boolval ( vm , line. clone ( ) ) ? {
523+ if !line. clone ( ) . try_to_bool ( vm ) ? {
524524 Err ( vm. new_stop_iteration ( ) )
525525 } else {
526526 Ok ( line)
@@ -1812,7 +1812,7 @@ mod _io {
18121812 fn isatty ( & self , vm : & VirtualMachine ) -> PyResult {
18131813 // read.isatty() or write.isatty()
18141814 let res = self . read . isatty ( vm) ?;
1815- if pybool :: boolval ( vm , res. clone ( ) ) ? {
1815+ if res. clone ( ) . try_to_bool ( vm ) ? {
18161816 Ok ( res)
18171817 } else {
18181818 self . write . isatty ( vm)
@@ -2208,11 +2208,11 @@ mod _io {
22082208 let buffer = args. buffer ;
22092209
22102210 let has_read1 = vm. get_attribute_opt ( buffer. clone ( ) , "read1" ) ?. is_some ( ) ;
2211- let seekable = pybool :: boolval ( vm , vm . call_method ( & buffer, "seekable" , ( ) ) ?) ?;
2211+ let seekable = vm . call_method ( & buffer, "seekable" , ( ) ) ?. try_to_bool ( vm ) ?;
22122212
22132213 let codec = vm. state . codec_registry . lookup ( encoding. as_str ( ) , vm) ?;
22142214
2215- let encoder = if pybool :: boolval ( vm , vm . call_method ( & buffer, "writable" , ( ) ) ?) ? {
2215+ let encoder = if vm . call_method ( & buffer, "writable" , ( ) ) ?. try_to_bool ( vm ) ? {
22162216 let incremental_encoder =
22172217 codec. get_incremental_encoder ( Some ( errors. clone ( ) ) , vm) ?;
22182218 let encoding_name = vm. get_attribute_opt ( incremental_encoder. clone ( ) , "name" ) ?;
@@ -2228,7 +2228,7 @@ mod _io {
22282228 None
22292229 } ;
22302230
2231- let decoder = if pybool :: boolval ( vm , vm . call_method ( & buffer, "readable" , ( ) ) ?) ? {
2231+ let decoder = if vm . call_method ( & buffer, "readable" , ( ) ) ?. try_to_bool ( vm ) ? {
22322232 let incremental_decoder =
22332233 codec. get_incremental_decoder ( Some ( errors. clone ( ) ) , vm) ?;
22342234 // TODO: wrap in IncrementalNewlineDecoder if newlines == Universal | Passthrough
0 commit comments