@@ -752,13 +752,22 @@ impl ExceptionZoo {
752752 let errno_getter =
753753 ctx. new_readonly_getset ( "errno" , excs. os_error , |exc : PyBaseExceptionRef | {
754754 let args = exc. args ( ) ;
755- args. get ( 0 ) . filter ( |_| args. len ( ) > 1 ) . cloned ( )
755+ args. get ( 0 )
756+ . filter ( |_| args. len ( ) > 1 && args. len ( ) <= 5 )
757+ . cloned ( )
758+ } ) ;
759+ let strerror_getter =
760+ ctx. new_readonly_getset ( "strerror" , excs. os_error , |exc : PyBaseExceptionRef | {
761+ let args = exc. args ( ) ;
762+ args. get ( 1 )
763+ . filter ( |_| args. len ( ) >= 2 && args. len ( ) <= 5 )
764+ . cloned ( )
756765 } ) ;
757766 extend_exception ! ( PyOSError , ctx, excs. os_error, {
758767 // POSIX exception code
759768 "errno" => errno_getter. clone( ) ,
760769 // exception strerror
761- "strerror" => ctx . new_readonly_getset ( "strerror" , excs . os_error , make_arg_getter ( 1 ) ) ,
770+ "strerror" => strerror_getter . clone ( ) ,
762771 // exception filename
763772 "filename" => ctx. none( ) ,
764773 // second exception filename
@@ -1260,15 +1269,15 @@ pub(super) mod types {
12601269 os_error,
12611270 "Base class for I/O related errors." ,
12621271 os_error_new,
1263- base_exception_init ,
1272+ os_error_init ,
12641273 }
12651274 #[ cfg( not( target_arch = "wasm32" ) ) ]
12661275 fn os_error_optional_new (
12671276 args : Vec < PyObjectRef > ,
12681277 vm : & VirtualMachine ,
12691278 ) -> Option < PyBaseExceptionRef > {
12701279 let len = args. len ( ) ;
1271- if len >= 2 {
1280+ if ( 2 ..= 5 ) . contains ( & len ) {
12721281 let errno = & args[ 0 ] ;
12731282 errno
12741283 . payload_if_subclass :: < PyInt > ( vm)
@@ -1297,9 +1306,18 @@ pub(super) mod types {
12971306 fn os_error_new ( cls : PyTypeRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
12981307 PyBaseException :: slot_new ( cls, args, vm)
12991308 }
1309+ fn os_error_init ( zelf : PyObjectRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult < ( ) > {
1310+ let len = args. args . len ( ) ;
1311+ let mut new_args = args;
1312+ if ( 3 ..=5 ) . contains ( & len) {
1313+ zelf. set_attr ( "filename" , new_args. args [ 2 ] . clone ( ) , vm) ?;
1314+ if len == 5 {
1315+ zelf. set_attr ( "filename2" , new_args. args [ 4 ] . clone ( ) , vm) ?;
1316+ }
13001317
1301- fn base_exception_init ( zelf : PyObjectRef , args : FuncArgs , vm : & VirtualMachine ) -> PyResult < ( ) > {
1302- PyBaseException :: init ( zelf, args, vm)
1318+ new_args. args . truncate ( 2 ) ;
1319+ }
1320+ PyBaseException :: init ( zelf, new_args, vm)
13031321 }
13041322
13051323 define_exception ! {
0 commit comments