@@ -591,6 +591,20 @@ extends_exception! {
591
591
"Common base class for all non-exit exceptions."
592
592
}
593
593
594
+ extends_exception ! {
595
+ PyGeneratorExit ,
596
+ PyBaseException ,
597
+ generator_exit,
598
+ "Request that a generator exit."
599
+ }
600
+
601
+ extends_exception ! {
602
+ PySystemExit ,
603
+ PyBaseException ,
604
+ system_exit,
605
+ "Request to exit from the interpreter."
606
+ }
607
+
594
608
extends_exception ! {
595
609
PyKeyboardInterrupt ,
596
610
PyBaseException ,
@@ -608,6 +622,20 @@ extends_exception! {
608
622
"Inappropriate argument type."
609
623
}
610
624
625
+ extends_exception ! {
626
+ PyStopAsyncIteration ,
627
+ PyException ,
628
+ stop_async_iteration,
629
+ "Signal the end from iterator.__anext__()."
630
+ }
631
+
632
+ extends_exception ! {
633
+ PyStopIteration ,
634
+ PyException ,
635
+ stop_iteration,
636
+ "Signal the end from iterator.__next__()."
637
+ }
638
+
611
639
extends_exception ! {
612
640
PyOSError ,
613
641
PyException ,
@@ -617,16 +645,16 @@ extends_exception! {
617
645
618
646
impl ExceptionZoo {
619
647
pub ( crate ) fn init ( ) -> Self {
648
+ // The same order as definitions:
620
649
let base_exception_type = PyBaseException :: init_bare_type ( ) . clone ( ) ;
650
+ let exception_type = PyException :: init_bare_type ( ) . clone ( ) ;
621
651
622
- // Sorted By Hierarchy then alphabetized.
623
- let system_exit = create_exception_type ( "SystemExit" , & base_exception_type) ;
652
+ let system_exit = PySystemExit :: init_bare_type ( ) . clone ( ) ;
624
653
let keyboard_interrupt = PyKeyboardInterrupt :: init_bare_type ( ) . clone ( ) ;
625
- let generator_exit = create_exception_type ( "GeneratorExit" , & base_exception_type ) ;
654
+ let generator_exit = PyGeneratorExit :: init_bare_type ( ) . clone ( ) ;
626
655
627
- let exception_type = PyException :: init_bare_type ( ) . clone ( ) ;
628
- let stop_iteration = create_exception_type ( "StopIteration" , & exception_type) ;
629
- let stop_async_iteration = create_exception_type ( "StopAsyncIteration" , & exception_type) ;
656
+ let stop_iteration = PyStopIteration :: init_bare_type ( ) . clone ( ) ;
657
+ let stop_async_iteration = PyStopAsyncIteration :: init_bare_type ( ) . clone ( ) ;
630
658
let arithmetic_error = create_exception_type ( "ArithmeticError" , & exception_type) ;
631
659
let floating_point_error = create_exception_type ( "FloatingPointError" , & arithmetic_error) ;
632
660
let overflow_error = create_exception_type ( "OverflowError" , & arithmetic_error) ;
@@ -776,9 +804,20 @@ impl ExceptionZoo {
776
804
777
805
PyBaseException :: extend_class ( ctx, & excs. base_exception_type ) ;
778
806
PyException :: extend_class ( ctx, & excs. exception_type ) ;
807
+
808
+ PyGeneratorExit :: extend_class ( ctx, & excs. generator_exit ) ;
809
+ PySystemExit :: extend_class ( ctx, & excs. system_exit ) ;
810
+ extend_class ! ( ctx, & excs. system_exit, {
811
+ "code" => ctx. new_readonly_getset( "code" , excs. system_exit. clone( ) , system_exit_code) ,
812
+ } ) ;
779
813
PyKeyboardInterrupt :: extend_class ( ctx, & excs. keyboard_interrupt ) ;
780
814
781
815
PyTypeError :: extend_class ( ctx, & excs. type_error ) ;
816
+ PyStopAsyncIteration :: extend_class ( ctx, & excs. stop_async_iteration ) ;
817
+ PyStopIteration :: extend_class ( ctx, & excs. stop_iteration ) ;
818
+ extend_class ! ( ctx, & excs. stop_iteration, {
819
+ "value" => ctx. new_readonly_getset( "value" , excs. stop_iteration. clone( ) , make_arg_getter( 0 ) ) ,
820
+ } ) ;
782
821
783
822
extend_class ! ( ctx, & excs. syntax_error, {
784
823
"msg" => ctx. new_readonly_getset( "msg" , excs. syntax_error. clone( ) , make_arg_getter( 0 ) ) ,
@@ -789,19 +828,11 @@ impl ExceptionZoo {
789
828
"text" => ctx. none( ) ,
790
829
} ) ;
791
830
792
- extend_class ! ( ctx, & excs. system_exit, {
793
- "code" => ctx. new_readonly_getset( "code" , excs. system_exit. clone( ) , system_exit_code) ,
794
- } ) ;
795
-
796
831
extend_class ! ( ctx, & excs. import_error, {
797
832
"__init__" => ctx. new_method( "__init__" , excs. import_error. clone( ) , import_error_init) ,
798
833
"msg" => ctx. new_readonly_getset( "msg" , excs. import_error. clone( ) , make_arg_getter( 0 ) ) ,
799
834
} ) ;
800
835
801
- extend_class ! ( ctx, & excs. stop_iteration, {
802
- "value" => ctx. new_readonly_getset( "value" , excs. stop_iteration. clone( ) , make_arg_getter( 0 ) ) ,
803
- } ) ;
804
-
805
836
extend_class ! ( ctx, & excs. key_error, {
806
837
"__str__" => ctx. new_method( "__str__" , excs. key_error. clone( ) , key_error_str) ,
807
838
} ) ;
0 commit comments