@@ -13,6 +13,7 @@ use crate::pyfunction::FunctionSignature;
13
13
use crate :: utils:: PyO3CratePath ;
14
14
use proc_macro2:: { Span , TokenStream } ;
15
15
use quote:: { format_ident, quote, ToTokens } ;
16
+ use std:: borrow:: Cow ;
16
17
use std:: collections:: hash_map:: DefaultHasher ;
17
18
use std:: collections:: HashMap ;
18
19
use std:: hash:: { Hash , Hasher } ;
@@ -30,9 +31,9 @@ pub fn module_introspection_code<'a>(
30
31
) -> TokenStream {
31
32
IntrospectionNode :: Map (
32
33
[
33
- ( "type" , IntrospectionNode :: String ( "module" ) ) ,
34
+ ( "type" , IntrospectionNode :: String ( "module" . into ( ) ) ) ,
34
35
( "id" , IntrospectionNode :: IntrospectionId ( None ) ) ,
35
- ( "name" , IntrospectionNode :: String ( name) ) ,
36
+ ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
36
37
(
37
38
"members" ,
38
39
IntrospectionNode :: List (
@@ -62,9 +63,9 @@ pub fn class_introspection_code(
62
63
) -> TokenStream {
63
64
IntrospectionNode :: Map (
64
65
[
65
- ( "type" , IntrospectionNode :: String ( "class" ) ) ,
66
+ ( "type" , IntrospectionNode :: String ( "class" . into ( ) ) ) ,
66
67
( "id" , IntrospectionNode :: IntrospectionId ( Some ( ident) ) ) ,
67
- ( "name" , IntrospectionNode :: String ( name) ) ,
68
+ ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
68
69
]
69
70
. into ( ) ,
70
71
)
@@ -79,9 +80,9 @@ pub fn function_introspection_code(
79
80
) -> TokenStream {
80
81
IntrospectionNode :: Map (
81
82
[
82
- ( "type" , IntrospectionNode :: String ( "function" ) ) ,
83
+ ( "type" , IntrospectionNode :: String ( "function" . into ( ) ) ) ,
83
84
( "id" , IntrospectionNode :: IntrospectionId ( Some ( ident) ) ) ,
84
- ( "name" , IntrospectionNode :: String ( name) ) ,
85
+ ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
85
86
( "arguments" , arguments_introspection_data ( signature) ) ,
86
87
]
87
88
. into ( ) ,
@@ -125,8 +126,8 @@ fn arguments_introspection_data<'a>(signature: &'a FunctionSignature<'a>) -> Int
125
126
if let Some ( param) = & signature. python_signature . varargs {
126
127
arguments. push ( IntrospectionNode :: Map (
127
128
[
128
- ( "name" , IntrospectionNode :: String ( param) ) ,
129
- ( "kind" , IntrospectionNode :: String ( "VAR_POSITIONAL" ) ) ,
129
+ ( "name" , IntrospectionNode :: String ( param. into ( ) ) ) ,
130
+ ( "kind" , IntrospectionNode :: String ( "VAR_POSITIONAL" . into ( ) ) ) ,
130
131
]
131
132
. into ( ) ,
132
133
) ) ;
@@ -144,8 +145,8 @@ fn arguments_introspection_data<'a>(signature: &'a FunctionSignature<'a>) -> Int
144
145
if let Some ( param) = & signature. python_signature . kwargs {
145
146
arguments. push ( IntrospectionNode :: Map (
146
147
[
147
- ( "name" , IntrospectionNode :: String ( param) ) ,
148
- ( "kind" , IntrospectionNode :: String ( "VAR_KEYWORD" ) ) ,
148
+ ( "name" , IntrospectionNode :: String ( param. into ( ) ) ) ,
149
+ ( "kind" , IntrospectionNode :: String ( "VAR_KEYWORD" . into ( ) ) ) ,
149
150
]
150
151
. into ( ) ,
151
152
) ) ;
@@ -160,19 +161,21 @@ fn argument_introspection_data<'a>(
160
161
desc : & ' a RegularArg < ' _ > ,
161
162
) -> IntrospectionNode < ' a > {
162
163
let mut params: HashMap < _ , _ > = [
163
- ( "name" , IntrospectionNode :: String ( name) ) ,
164
- ( "kind" , IntrospectionNode :: String ( kind) ) ,
164
+ ( "name" , IntrospectionNode :: String ( name. into ( ) ) ) ,
165
+ ( "kind" , IntrospectionNode :: String ( kind. into ( ) ) ) ,
165
166
]
166
167
. into ( ) ;
167
168
if desc. default_value . is_some ( ) {
168
- // TODO: generate a nice default values for literals (None, false, 0, ""...)
169
- params. insert ( "default_value" , IntrospectionNode :: String ( "..." ) ) ;
169
+ params. insert (
170
+ "default_value" ,
171
+ IntrospectionNode :: String ( desc. default_value ( ) . into ( ) ) ,
172
+ ) ;
170
173
}
171
174
IntrospectionNode :: Map ( params)
172
175
}
173
176
174
177
enum IntrospectionNode < ' a > {
175
- String ( & ' a str ) ,
178
+ String ( Cow < ' a , str > ) ,
176
179
IntrospectionId ( Option < & ' a Ident > ) ,
177
180
Map ( HashMap < & ' static str , IntrospectionNode < ' a > > ) ,
178
181
List ( Vec < IntrospectionNode < ' a > > ) ,
@@ -198,7 +201,7 @@ impl IntrospectionNode<'_> {
198
201
fn add_to_serialization ( self , content : & mut ConcatenationBuilder ) {
199
202
match self {
200
203
Self :: String ( string) => {
201
- content. push_str_to_escape ( string) ;
204
+ content. push_str_to_escape ( & string) ;
202
205
}
203
206
Self :: IntrospectionId ( ident) => {
204
207
content. push_str ( "\" " ) ;
0 commit comments