@@ -82,6 +82,7 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
82
82
args,
83
83
body,
84
84
decorator_list,
85
+ returns,
85
86
} => {
86
87
let node = create_node ( ctx, "FunctionDef" ) ;
87
88
@@ -96,6 +97,13 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
96
97
97
98
let py_decorator_list = expressions_to_ast ( ctx, decorator_list) ;
98
99
ctx. set_attr ( & node, "decorator_list" , py_decorator_list) ;
100
+
101
+ let py_returns = if let Some ( hint) = returns {
102
+ expression_to_ast ( ctx, hint)
103
+ } else {
104
+ ctx. none ( )
105
+ } ;
106
+ ctx. set_attr ( & node, "returns" , py_returns) ;
99
107
node
100
108
}
101
109
ast:: Statement :: Continue => create_node ( ctx, "Continue" ) ,
@@ -537,17 +545,28 @@ fn parameters_to_ast(ctx: &PyContext, args: &ast::Parameters) -> PyObjectRef {
537
545
ctx. set_attr (
538
546
& node,
539
547
"args" ,
540
- ctx. new_list (
541
- args. args
542
- . iter ( )
543
- . map ( |a| ctx. new_str ( a. arg . to_string ( ) ) )
544
- . collect ( ) ,
545
- ) ,
548
+ ctx. new_list ( args. args . iter ( ) . map ( |a| parameter_to_ast ( ctx, a) ) . collect ( ) ) ,
546
549
) ;
547
550
548
551
node
549
552
}
550
553
554
+ fn parameter_to_ast ( ctx : & PyContext , parameter : & ast:: Parameter ) -> PyObjectRef {
555
+ let node = create_node ( ctx, "arg" ) ;
556
+
557
+ let py_arg = ctx. new_str ( parameter. arg . to_string ( ) ) ;
558
+ ctx. set_attr ( & node, "arg" , py_arg) ;
559
+
560
+ let py_annotation = if let Some ( annotation) = & parameter. annotation {
561
+ expression_to_ast ( ctx, annotation)
562
+ } else {
563
+ ctx. none ( )
564
+ } ;
565
+ ctx. set_attr ( & node, "annotation" , py_annotation) ;
566
+
567
+ node
568
+ }
569
+
551
570
fn comprehension_to_ast ( ctx : & PyContext , comprehension : & ast:: Comprehension ) -> PyObjectRef {
552
571
let node = create_node ( ctx, "comprehension" ) ;
553
572
0 commit comments