@@ -230,9 +230,55 @@ macro_rules! create_exception_type_object {
230230 ) . as_ptr( ) as * mut $crate:: ffi:: PyTypeObject
231231 }
232232 }
233+
234+ $crate:: create_exception_introspection_data!( $module, $name, $base) ;
233235 } ;
234236}
235237
238+ /// Adds some introspection data for the exception if the `experimental-inspect` feature is enabled.
239+ #[ cfg( not( feature = "experimental-inspect" ) ) ]
240+ #[ doc( hidden) ]
241+ #[ macro_export]
242+ macro_rules! create_exception_introspection_data(
243+ ( $module: expr, $name: ident, $base: ty) => { } ;
244+ ) ;
245+
246+ #[ cfg( feature = "experimental-inspect" ) ]
247+ #[ doc( hidden) ]
248+ #[ macro_export]
249+ macro_rules! create_exception_introspection_data(
250+ ( $module: expr, $name: ident, $base: ty) => {
251+ const _: ( ) = {
252+ const PIECES : & [ & [ u8 ] ] = & [
253+ b"{\" type\" :\" class\" ,\" id\" :\" " ,
254+ $name:: _PYO3_INTROSPECTION_ID. as_bytes( ) ,
255+ b"\" ,\" name\" :\" " ,
256+ stringify!( $name) . as_bytes( ) ,
257+ b"\" ,\" bases\" :[" ,
258+ {
259+ const BASE_LEN : usize = $crate:: inspect:: serialized_len_for_introspection( & <$base as $crate:: type_object:: PyTypeInfo >:: TYPE_HINT ) ;
260+ const BASE_SER : [ u8 ; BASE_LEN ] = {
261+ let mut result: [ u8 ; BASE_LEN ] = [ 0 ; BASE_LEN ] ;
262+ $crate:: inspect:: serialize_for_introspection( & <$base as $crate:: type_object:: PyTypeInfo >:: TYPE_HINT , & mut result) ;
263+ result
264+ } ;
265+ & BASE_SER
266+ } ,
267+ b"]}"
268+ ] ;
269+ const PIECES_LEN : usize = $crate:: impl_:: concat:: combined_len( PIECES ) ;
270+ $crate:: impl_:: introspection:: paste! {
271+ #[ used]
272+ #[ no_mangle]
273+ static [ <PYO3_INTROSPECTION_1_ $name>] : $crate:: impl_:: introspection:: SerializedIntrospectionFragment <PIECES_LEN > = $crate:: impl_:: introspection:: SerializedIntrospectionFragment {
274+ length: PIECES_LEN as u32 ,
275+ fragment: $crate:: impl_:: concat:: combine_to_array:: <PIECES_LEN >( PIECES )
276+ } ;
277+ }
278+ } ;
279+ } ;
280+ ) ;
281+
236282macro_rules! impl_native_exception (
237283 ( $name: ident, $exc_name: ident, $python_name: expr, $doc: expr, $layout: path $( , #checkfunction=$checkfunction: path) ?) => (
238284 #[ doc = $doc]
0 commit comments