@@ -643,6 +643,19 @@ extends_exception! {
643
643
"Base class for I/O related errors."
644
644
}
645
645
646
+ macro_rules! extend_exception {
647
+ ( $ctx: expr, $class: expr, { $( $name: expr => $value: expr) ,* $( , ) * } ) => {
648
+ $class. set_str_attr( "__new__" , $ctx. new_method( "__new__" , $class. clone( ) , PyBaseException :: tp_new) ) ;
649
+ $class. set_str_attr( "__init__" , $ctx. new_method( "__init__" , $class. clone( ) , PyBaseException :: init) ) ;
650
+
651
+ extend_class!( $ctx, $class, {
652
+ $(
653
+ $name => $value,
654
+ ) *
655
+ } ) ;
656
+ } ;
657
+ }
658
+
646
659
impl ExceptionZoo {
647
660
pub ( crate ) fn init ( ) -> Self {
648
661
// The same order as definitions:
@@ -819,6 +832,8 @@ impl ExceptionZoo {
819
832
"value" => ctx. new_readonly_getset( "value" , excs. stop_iteration. clone( ) , make_arg_getter( 0 ) ) ,
820
833
} ) ;
821
834
835
+ extend_exception ! ( ctx, & excs. arithmetic_error, { } ) ;
836
+
822
837
extend_class ! ( ctx, & excs. syntax_error, {
823
838
"msg" => ctx. new_readonly_getset( "msg" , excs. syntax_error. clone( ) , make_arg_getter( 0 ) ) ,
824
839
// TODO: members
@@ -828,7 +843,7 @@ impl ExceptionZoo {
828
843
"text" => ctx. none( ) ,
829
844
} ) ;
830
845
831
- extend_class ! ( ctx, & excs. import_error, {
846
+ extend_exception ! ( ctx, & excs. import_error, {
832
847
"__init__" => ctx. new_method( "__init__" , excs. import_error. clone( ) , import_error_init) ,
833
848
"msg" => ctx. new_readonly_getset( "msg" , excs. import_error. clone( ) , make_arg_getter( 0 ) ) ,
834
849
} ) ;
0 commit comments