File tree Expand file tree Collapse file tree 1 file changed +10
-18
lines changed
Expand file tree Collapse file tree 1 file changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -265,14 +265,21 @@ impl VirtualMachine {
265265 }
266266
267267 pub fn new_stop_iteration ( & self , value : Option < PyObjectRef > ) -> PyBaseExceptionRef {
268+ let dict = self . ctx . new_dict ( ) ;
268269 let args = if let Some ( value) = value {
270+ // manually set `value` attribute like StopIteration.__init__
271+ dict. set_item ( "value" , value. clone ( ) , self )
272+ . expect ( "dict.__setitem__ never fails" ) ;
269273 vec ! [ value]
270274 } else {
271275 Vec :: new ( )
272276 } ;
273- let exc = self . new_exception ( self . ctx . exceptions . stop_iteration . to_owned ( ) , args. clone ( ) ) ;
274- // To initialize the `value` attribute to first argument
275- self . set_exception_attr ( exc, "value" , args. get ( 0 ) . cloned ( ) )
277+
278+ PyRef :: new_ref (
279+ PyBaseException :: new ( args, self ) ,
280+ self . ctx . exceptions . stop_iteration . to_owned ( ) ,
281+ Some ( dict) ,
282+ )
276283 }
277284
278285 fn new_downcast_error (
@@ -314,19 +321,4 @@ impl VirtualMachine {
314321 obj. as_object ( ) ,
315322 )
316323 }
317-
318- fn set_exception_attr (
319- & self ,
320- exc : PyBaseExceptionRef ,
321- attr_name : & str ,
322- attr_value : Option < PyObjectRef > ,
323- ) -> PyBaseExceptionRef {
324- match exc
325- . as_object ( )
326- . set_attr ( attr_name, self . unwrap_or_none ( attr_value) , self )
327- {
328- Ok ( _) => exc,
329- Err ( e) => e,
330- }
331- }
332324}
You can’t perform that action at this time.
0 commit comments