@@ -14,22 +14,14 @@ use crate::{
1414} ;
1515
1616macro_rules! define_exception_fn {
17- // With doc
1817 (
19- fn $fn_name: ident, $attr: ident,
20- doc = $doc: literal
21- ) => {
22- #[ doc = $doc]
23- pub fn $fn_name( & self , msg: String ) -> PyBaseExceptionRef {
24- let err = self . ctx. exceptions. $attr. to_owned( ) ;
25- self . new_exception_msg( err, msg)
26- }
27- } ;
28-
29- // Without doc
30- (
31- $fn_name: ident, $attr: ident
18+ fn $fn_name: ident, $attr: ident, $python_repr: ident
3219 ) => {
20+ #[ doc = concat!(
21+ "Create a new python " ,
22+ stringify!( $python_repr) ,
23+ " object.\n Useful for raising errors from python functions implemented in rust."
24+ ) ]
3325 pub fn $fn_name( & self , msg: String ) -> PyBaseExceptionRef {
3426 let err = self . ctx. exceptions. $attr. to_owned( ) ;
3527 self . new_exception_msg( err, msg)
@@ -547,32 +539,31 @@ impl VirtualMachine {
547539 )
548540 }
549541
550- define_exception_fn ! ( new_lookup_error, lookup_error) ;
551- define_exception_fn ! ( new_eof_error, eof_error) ;
552- define_exception_fn ! ( new_attribute_error, attribute_error) ;
553- define_exception_fn ! ( new_type_error, type_error) ;
554- define_exception_fn ! ( new_os_error, os_error) ;
555- define_exception_fn ! ( new_system_error, system_error) ;
542+ define_exception_fn ! ( fn new_lookup_error, lookup_error, LookupError ) ;
543+ define_exception_fn ! ( fn new_eof_error, eof_error, EOFError ) ;
544+ define_exception_fn ! ( fn new_attribute_error, attribute_error, AttributeError ) ;
545+ define_exception_fn ! ( fn new_type_error, type_error, TypeError ) ;
546+ define_exception_fn ! ( fn new_os_error, os_error, OSError ) ;
547+ define_exception_fn ! ( fn new_system_error, system_error, SystemError ) ;
556548
557549 // TODO: remove & replace with new_unicode_decode_error_real
558- define_exception_fn ! ( new_unicode_decode_error, unicode_decode_error) ;
550+ define_exception_fn ! ( fn new_unicode_decode_error, unicode_decode_error, UnicodeDecodeError ) ;
559551
560552 // TODO: remove & replace with new_unicode_encode_error_real
561- define_exception_fn ! ( new_unicode_encode_error, unicode_encode_error) ;
553+ define_exception_fn ! ( fn new_unicode_encode_error, unicode_encode_error, UnicodeEncodeError ) ;
562554
555+ define_exception_fn ! ( fn new_value_error, value_error, ValueError ) ;
556+
557+ define_exception_fn ! ( fn new_buffer_error, buffer_error, BufferError ) ;
558+ define_exception_fn ! ( fn new_index_error, index_error, IndexError ) ;
563559 define_exception_fn ! (
564- new_value_error,
565- value_error,
566- doc = "Create a new python ValueError object.
567- Useful for raising errors from python functions implemented in rust."
560+ fn new_not_implemented_error,
561+ not_implemented_error,
562+ NotImplementedError
568563 ) ;
569-
570- define_exception_fn ! ( new_buffer_error, buffer_error) ;
571- define_exception_fn ! ( new_index_error, index_error) ;
572- define_exception_fn ! ( new_not_implemented_error, not_implemented_error) ;
573- define_exception_fn ! ( new_recursion_error, recursion_error) ;
574- define_exception_fn ! ( new_zero_division_error, zero_division_error) ;
575- define_exception_fn ! ( new_overflow_error, overflow_error) ;
576- define_exception_fn ! ( new_runtime_error, runtime_error) ;
577- define_exception_fn ! ( new_memory_error, memory_error) ;
564+ define_exception_fn ! ( fn new_recursion_error, recursion_error, RecursionError ) ;
565+ define_exception_fn ! ( fn new_zero_division_error, zero_division_error, ZeroDivisionError ) ;
566+ define_exception_fn ! ( fn new_overflow_error, overflow_error, OverflowError ) ;
567+ define_exception_fn ! ( fn new_runtime_error, runtime_error, RuntimeError ) ;
568+ define_exception_fn ! ( fn new_memory_error, memory_error, MemoryError ) ;
578569}
0 commit comments