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):
23492349
23502350
23512351class ImportErrorTests (unittest .TestCase ):
2352- # TODO: RUSTPYTHON
2353- @unittest .expectedFailure
23542352 def test_attributes (self ):
23552353 # Setting 'name' and 'path' should not be a problem.
23562354 exc = ImportError ('test' )
@@ -2385,8 +2383,6 @@ def test_attributes(self):
23852383 with self .assertRaisesRegex (TypeError , msg ):
23862384 ImportError ('test' , invalid = 'keyword' , another = True )
23872385
2388- # TODO: RUSTPYTHON
2389- @unittest .expectedFailure
23902386 def test_reset_attributes (self ):
23912387 exc = ImportError ('test' , name = 'name' , path = 'path' )
23922388 self .assertEqual (exc .args , ('test' ,))
Original file line number Diff line number Diff line change @@ -1308,17 +1308,21 @@ pub(super) mod types {
13081308 args : :: rustpython_vm:: function:: FuncArgs ,
13091309 vm : & :: rustpython_vm:: VirtualMachine ,
13101310 ) -> :: 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)
13221326 }
13231327 #[ pymethod( magic) ]
13241328 fn reduce ( exc : PyBaseExceptionRef , vm : & VirtualMachine ) -> PyTupleRef {
You can’t perform that action at this time.
0 commit comments