@@ -82,6 +82,7 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
8282 args,
8383 body,
8484 decorator_list,
85+ returns,
8586 } => {
8687 let node = create_node ( ctx, "FunctionDef" ) ;
8788
@@ -96,6 +97,13 @@ fn statement_to_ast(ctx: &PyContext, statement: &ast::LocatedStatement) -> PyObj
9697
9798 let py_decorator_list = expressions_to_ast ( ctx, decorator_list) ;
9899 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) ;
99107 node
100108 }
101109 ast:: Statement :: Continue => create_node ( ctx, "Continue" ) ,
@@ -537,17 +545,28 @@ fn parameters_to_ast(ctx: &PyContext, args: &ast::Parameters) -> PyObjectRef {
537545 ctx. set_attr (
538546 & node,
539547 "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 ( ) ) ,
546549 ) ;
547550
548551 node
549552}
550553
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+
551570fn comprehension_to_ast ( ctx : & PyContext , comprehension : & ast:: Comprehension ) -> PyObjectRef {
552571 let node = create_node ( ctx, "comprehension" ) ;
553572
0 commit comments