4
4
//! The generated structures are read-only.
5
5
6
6
use proc_macro2:: { Ident , Literal , TokenStream , TokenTree } ;
7
- use quote:: { format_ident, quote} ;
7
+ use quote:: { format_ident, quote, ToTokens } ;
8
8
use syn:: spanned:: Spanned ;
9
9
use syn:: Type ;
10
10
use crate :: method:: FnType ;
@@ -89,6 +89,7 @@ pub(crate) fn generate_fields_inspection(
89
89
90
90
let field_info_name = format_ident ! ( "{}_info" , ident_prefix) ;
91
91
let field_args_name = format_ident ! ( "{}_args" , ident_prefix) ;
92
+ let field_type_fn_name = format_ident ! ( "{}_output_fn" , ident_prefix) ;
92
93
93
94
let field_name = TokenTree :: Literal ( Literal :: string ( & * field. method_name ) ) ;
94
95
let field_kind = match & field. spec . tp {
@@ -101,14 +102,24 @@ pub(crate) fn generate_fields_inspection(
101
102
FnType :: FnModule => todo ! ( "FnModule is not currently supported" ) ,
102
103
FnType :: ClassAttribute => quote ! ( _pyo3:: inspect:: fields:: FieldKind :: ClassAttribute ) ,
103
104
} ;
105
+ let field_type = match & field. spec . output {
106
+ Type :: Path ( path) if path. path . get_ident ( ) . filter ( |i| i. to_string ( ) == "Self" ) . is_some ( ) => {
107
+ cls. to_token_stream ( )
108
+ }
109
+ other => other. to_token_stream ( ) ,
110
+ } ;
104
111
105
112
let output = quote ! {
113
+ fn #field_type_fn_name( ) -> _pyo3:: inspect:: types:: TypeInfo {
114
+ <#field_type as _pyo3:: conversion:: IntoPy <_>>:: type_output( )
115
+ }
116
+
106
117
const #field_args_name: [ _pyo3:: inspect:: fields:: ArgumentInfo <' static >; 0 ] = [ ] ; //TODO
107
118
108
119
const #field_info_name: _pyo3:: inspect:: fields:: FieldInfo <' static > = _pyo3:: inspect:: fields:: FieldInfo {
109
120
name: #field_name,
110
121
kind: #field_kind,
111
- py_type: :: std :: option :: Option :: None , //TODO
122
+ py_type: Some ( #field_type_fn_name ) ,
112
123
arguments: & #field_args_name,
113
124
} ;
114
125
} ;
0 commit comments