@@ -20,7 +20,7 @@ use std::hash::{Hash, Hasher};
20
20
use std:: mem:: take;
21
21
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
22
22
use syn:: visit_mut:: { visit_type_mut, VisitMut } ;
23
- use syn:: { Attribute , Ident , ReturnType , Type , TypePath } ;
23
+ use syn:: { Attribute , Ident , Path , ReturnType , Type , TypePath } ;
24
24
25
25
static GLOBAL_COUNTER_FOR_UNIQUE_NAMES : AtomicUsize = AtomicUsize :: new ( 0 ) ;
26
26
@@ -61,19 +61,23 @@ pub fn class_introspection_code(
61
61
pyo3_crate_path : & PyO3CratePath ,
62
62
ident : & Ident ,
63
63
name : & str ,
64
+ extends : Option < & Path > ,
64
65
) -> TokenStream {
65
- IntrospectionNode :: Map (
66
- [
67
- ( "type" , IntrospectionNode :: String ( "class" . into ( ) ) ) ,
68
- (
69
- "id" ,
70
- IntrospectionNode :: IntrospectionId ( Some ( ident_to_type ( ident) ) ) ,
71
- ) ,
72
- ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
73
- ]
74
- . into ( ) ,
75
- )
76
- . emit ( pyo3_crate_path)
66
+ let mut desc = HashMap :: from ( [
67
+ ( "type" , IntrospectionNode :: String ( "class" . into ( ) ) ) ,
68
+ (
69
+ "id" ,
70
+ IntrospectionNode :: IntrospectionId ( Some ( ident_to_type ( ident) ) ) ,
71
+ ) ,
72
+ ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
73
+ ] ) ;
74
+ if let Some ( extends) = extends {
75
+ desc. insert (
76
+ "bases" ,
77
+ IntrospectionNode :: List ( vec ! [ IntrospectionNode :: BaseType ( extends) . into( ) ] ) ,
78
+ ) ;
79
+ }
80
+ IntrospectionNode :: Map ( desc) . emit ( pyo3_crate_path)
77
81
}
78
82
79
83
#[ allow( clippy:: too_many_arguments) ]
@@ -345,6 +349,7 @@ enum IntrospectionNode<'a> {
345
349
IntrospectionId ( Option < Cow < ' a , Type > > ) ,
346
350
InputType { rust_type : Type , nullable : bool } ,
347
351
OutputType { rust_type : Type , is_final : bool } ,
352
+ BaseType ( & ' a Path ) ,
348
353
Map ( HashMap < & ' static str , IntrospectionNode < ' a > > ) ,
349
354
List ( Vec < AttributedIntrospectionNode < ' a > > ) ,
350
355
}
@@ -410,6 +415,13 @@ impl IntrospectionNode<'_> {
410
415
}
411
416
content. push_str ( "\" " ) ;
412
417
}
418
+ Self :: BaseType ( path) => {
419
+ content. push_str ( "\" " ) ;
420
+ content. push_tokens (
421
+ quote ! { <#path as #pyo3_crate_path:: impl_:: pyclass:: PyClassBaseType >:: BASE_NAME . as_bytes( ) } ,
422
+ ) ;
423
+ content. push_str ( "\" " ) ;
424
+ }
413
425
Self :: Map ( map) => {
414
426
content. push_str ( "{" ) ;
415
427
for ( i, ( key, value) ) in map. into_iter ( ) . enumerate ( ) {
0 commit comments