@@ -20,7 +20,7 @@ use std::hash::{Hash, Hasher};
2020use std:: mem:: take;
2121use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
2222use syn:: visit_mut:: { visit_type_mut, VisitMut } ;
23- use syn:: { Attribute , Ident , Lifetime , ReturnType , Type , TypePath } ;
23+ use syn:: { Attribute , Ident , Lifetime , Path , ReturnType , Type , TypePath } ;
2424
2525static GLOBAL_COUNTER_FOR_UNIQUE_NAMES : AtomicUsize = AtomicUsize :: new ( 0 ) ;
2626
@@ -89,6 +89,7 @@ pub fn class_introspection_code(
8989 pyo3_crate_path : & PyO3CratePath ,
9090 ident : & Ident ,
9191 name : & str ,
92+ extends : Option < & Path > ,
9293 is_final : bool ,
9394) -> TokenStream {
9495 let mut desc = HashMap :: from ( [
@@ -99,6 +100,12 @@ pub fn class_introspection_code(
99100 ) ,
100101 ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
101102 ] ) ;
103+ if let Some ( extends) = extends {
104+ desc. insert (
105+ "bases" ,
106+ IntrospectionNode :: List ( vec ! [ IntrospectionNode :: BaseType ( extends) . into( ) ] ) ,
107+ ) ;
108+ }
102109 if is_final {
103110 desc. insert (
104111 "decorators" ,
@@ -355,6 +362,7 @@ enum IntrospectionNode<'a> {
355362 IntrospectionId ( Option < Cow < ' a , Type > > ) ,
356363 InputType ( Type ) ,
357364 OutputType { rust_type : Type , is_final : bool } ,
365+ BaseType ( & ' a Path ) ,
358366 ConstantType ( PythonIdentifier ) ,
359367 Map ( HashMap < & ' static str , IntrospectionNode < ' a > > ) ,
360368 List ( Vec < AttributedIntrospectionNode < ' a > > ) ,
@@ -411,6 +419,11 @@ impl IntrospectionNode<'_> {
411419 }
412420 content. push_tokens ( serialize_type_hint ( annotation, pyo3_crate_path) ) ;
413421 }
422+ Self :: BaseType ( rust_type) => {
423+ let annotation =
424+ quote ! { <#rust_type as #pyo3_crate_path:: type_object:: PyTypeInfo >:: TYPE_HINT } ;
425+ content. push_tokens ( serialize_type_hint ( annotation, pyo3_crate_path) ) ;
426+ }
414427 Self :: ConstantType ( hint) => {
415428 let name = & hint. name ;
416429 let annotation = if let Some ( module) = & hint. module {
0 commit comments