File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -2349,8 +2349,6 @@ def __getattribute__(self, attr):
2349
2349
2350
2350
2351
2351
class ImportErrorTests (unittest .TestCase ):
2352
- # TODO: RUSTPYTHON
2353
- @unittest .expectedFailure
2354
2352
def test_attributes (self ):
2355
2353
# Setting 'name' and 'path' should not be a problem.
2356
2354
exc = ImportError ('test' )
@@ -2385,8 +2383,6 @@ def test_attributes(self):
2385
2383
with self .assertRaisesRegex (TypeError , msg ):
2386
2384
ImportError ('test' , invalid = 'keyword' , another = True )
2387
2385
2388
- # TODO: RUSTPYTHON
2389
- @unittest .expectedFailure
2390
2386
def test_reset_attributes (self ):
2391
2387
exc = ImportError ('test' , name = 'name' , path = 'path' )
2392
2388
self .assertEqual (exc .args , ('test' ,))
Original file line number Diff line number Diff line change @@ -1308,17 +1308,21 @@ pub(super) mod types {
1308
1308
args : :: rustpython_vm:: function:: FuncArgs ,
1309
1309
vm : & :: rustpython_vm:: VirtualMachine ,
1310
1310
) -> :: rustpython_vm:: PyResult < ( ) > {
1311
- zelf. set_attr (
1312
- "name" ,
1313
- vm. unwrap_or_none ( args. kwargs . get ( "name" ) . cloned ( ) ) ,
1314
- vm,
1315
- ) ?;
1316
- zelf. set_attr (
1317
- "path" ,
1318
- vm. unwrap_or_none ( args. kwargs . get ( "path" ) . cloned ( ) ) ,
1319
- vm,
1320
- ) ?;
1321
- Ok ( ( ) )
1311
+ let mut kwargs = args. kwargs . clone ( ) ;
1312
+ let name = kwargs. swap_remove ( "name" ) ;
1313
+ let path = kwargs. swap_remove ( "path" ) ;
1314
+
1315
+ // Check for any remaining invalid keyword arguments
1316
+ if let Some ( invalid_key) = kwargs. keys ( ) . next ( ) {
1317
+ return Err ( vm. new_type_error ( format ! (
1318
+ "'{}' is an invalid keyword argument for ImportError" ,
1319
+ invalid_key
1320
+ ) ) ) ;
1321
+ }
1322
+
1323
+ zelf. set_attr ( "name" , vm. unwrap_or_none ( name) , vm) ?;
1324
+ zelf. set_attr ( "path" , vm. unwrap_or_none ( path) , vm) ?;
1325
+ PyBaseException :: slot_init ( zelf, args, vm)
1322
1326
}
1323
1327
#[ pymethod( magic) ]
1324
1328
fn reduce ( exc : PyBaseExceptionRef , vm : & VirtualMachine ) -> PyTupleRef {
You can’t perform that action at this time.
0 commit comments