@@ -433,6 +433,11 @@ fn set_pop(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
433
433
}
434
434
435
435
fn set_update ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
436
+ set_ior ( vm, args) ?;
437
+ Ok ( vm. get_none ( ) )
438
+ }
439
+
440
+ fn set_ior ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
436
441
arg_check ! (
437
442
vm,
438
443
args,
@@ -447,17 +452,27 @@ fn set_update(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
447
452
while let Ok ( v) = vm. call_method ( & iterator, "__next__" , vec ! [ ] ) {
448
453
insert_into_set ( vm, elements, & v) ?;
449
454
}
450
- Ok ( vm. get_none ( ) )
451
455
}
452
- _ => Err ( vm. new_type_error ( "set.update is called with no other" . to_string ( ) ) ) ,
456
+ _ => return Err ( vm. new_type_error ( "set.update is called with no other" . to_string ( ) ) ) ,
453
457
}
458
+ Ok ( zelf. clone ( ) )
454
459
}
455
460
456
461
fn set_intersection_update ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
462
+ set_combine_update_inner ( vm, args, SetCombineOperation :: Intersection ) ?;
463
+ Ok ( vm. get_none ( ) )
464
+ }
465
+
466
+ fn set_iand ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
457
467
set_combine_update_inner ( vm, args, SetCombineOperation :: Intersection )
458
468
}
459
469
460
470
fn set_difference_update ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
471
+ set_combine_update_inner ( vm, args, SetCombineOperation :: Difference ) ?;
472
+ Ok ( vm. get_none ( ) )
473
+ }
474
+
475
+ fn set_isub ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
461
476
set_combine_update_inner ( vm, args, SetCombineOperation :: Difference )
462
477
}
463
478
@@ -486,13 +501,18 @@ fn set_combine_update_inner(
486
501
elements. remove ( & element. 0 . clone ( ) ) ;
487
502
}
488
503
}
489
- Ok ( vm. get_none ( ) )
490
504
}
491
- _ => Err ( vm. new_type_error ( "" . to_string ( ) ) ) ,
505
+ _ => return Err ( vm. new_type_error ( "" . to_string ( ) ) ) ,
492
506
}
507
+ Ok ( zelf. clone ( ) )
493
508
}
494
509
495
510
fn set_symmetric_difference_update ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
511
+ set_ixor ( vm, args) ?;
512
+ Ok ( vm. get_none ( ) )
513
+ }
514
+
515
+ fn set_ixor ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
496
516
arg_check ! (
497
517
vm,
498
518
args,
@@ -514,11 +534,27 @@ fn set_symmetric_difference_update(vm: &mut VirtualMachine, args: PyFuncArgs) ->
514
534
elements. remove ( & element. 0 . clone ( ) ) ;
515
535
}
516
536
}
517
-
518
- Ok ( vm. get_none ( ) )
519
537
}
520
- _ => Err ( vm. new_type_error ( "" . to_string ( ) ) ) ,
538
+ _ => return Err ( vm. new_type_error ( "" . to_string ( ) ) ) ,
521
539
}
540
+
541
+ Ok ( zelf. clone ( ) )
542
+ }
543
+
544
+ fn set_iter ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
545
+ arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. set_type( ) ) ) ] ) ;
546
+
547
+ let items = get_elements ( zelf) . values ( ) . map ( |x| x. clone ( ) ) . collect ( ) ;
548
+ let set_list = vm. ctx . new_list ( items) ;
549
+ let iter_obj = PyObject :: new (
550
+ PyObjectPayload :: Iterator {
551
+ position : 0 ,
552
+ iterated_obj : set_list,
553
+ } ,
554
+ vm. ctx . iter_type ( ) ,
555
+ ) ;
556
+
557
+ Ok ( iter_obj)
522
558
}
523
559
524
560
fn frozenset_repr ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
@@ -593,21 +629,26 @@ pub fn init(context: &PyContext) {
593
629
context. set_attr ( & set_type, "copy" , context. new_rustfunc ( set_copy) ) ;
594
630
context. set_attr ( & set_type, "pop" , context. new_rustfunc ( set_pop) ) ;
595
631
context. set_attr ( & set_type, "update" , context. new_rustfunc ( set_update) ) ;
632
+ context. set_attr ( & set_type, "__ior__" , context. new_rustfunc ( set_ior) ) ;
596
633
context. set_attr (
597
634
& set_type,
598
635
"intersection_update" ,
599
636
context. new_rustfunc ( set_intersection_update) ,
600
637
) ;
638
+ context. set_attr ( & set_type, "__iand__" , context. new_rustfunc ( set_iand) ) ;
601
639
context. set_attr (
602
640
& set_type,
603
641
"difference_update" ,
604
642
context. new_rustfunc ( set_difference_update) ,
605
643
) ;
644
+ context. set_attr ( & set_type, "__isub__" , context. new_rustfunc ( set_isub) ) ;
606
645
context. set_attr (
607
646
& set_type,
608
647
"symmetric_difference_update" ,
609
648
context. new_rustfunc ( set_symmetric_difference_update) ,
610
649
) ;
650
+ context. set_attr ( & set_type, "__ixor__" , context. new_rustfunc ( set_ixor) ) ;
651
+ context. set_attr ( & set_type, "__iter__" , context. new_rustfunc ( set_iter) ) ;
611
652
612
653
let frozenset_type = & context. frozenset_type ;
613
654
0 commit comments