@@ -111,7 +111,7 @@ mod _io {
111111 } ,
112112 convert:: ToPyObject ,
113113 function:: {
114- ArgBytesLike , ArgIterable , ArgMemoryBuffer , Either , FuncArgs , IntoFuncArgs ,
114+ ArgBytesLike , ArgIterable , ArgMemoryBuffer , ArgSize , Either , FuncArgs , IntoFuncArgs ,
115115 OptionalArg , OptionalOption , PySetterValue ,
116116 } ,
117117 protocol:: {
@@ -169,7 +169,7 @@ mod _io {
169169 // In a few functions, the default value is -1 rather than None.
170170 // Make sure the default value doesn't affect compatibility.
171171 #[ pyarg( positional, default ) ]
172- size : Option < isize > ,
172+ size : Option < ArgSize > ,
173173 }
174174
175175 impl OptionalSize {
@@ -181,6 +181,7 @@ mod _io {
181181 pub fn try_usize ( self , vm : & VirtualMachine ) -> PyResult < Option < usize > > {
182182 self . size
183183 . map ( |v| {
184+ let v = * v;
184185 if v >= 0 {
185186 Ok ( v as usize )
186187 } else {
@@ -1597,7 +1598,7 @@ mod _io {
15971598 fn read ( & self , size : OptionalSize , vm : & VirtualMachine ) -> PyResult < Option < PyBytesRef > > {
15981599 let mut data = self . reader ( ) . lock ( vm) ?;
15991600 let raw = data. check_init ( vm) ?;
1600- let n = size. size . unwrap_or ( -1 ) ;
1601+ let n = size. size . map ( |s| * s ) . unwrap_or ( -1 ) ;
16011602 if n < -1 {
16021603 return Err ( vm. new_value_error ( "read length must be non-negative or -1" . to_owned ( ) ) ) ;
16031604 }
0 commit comments