@@ -85,6 +85,7 @@ fn module_stubs(module: &Module, parents: &[&str]) -> String {
8585 } ) ,
8686 attr : "Incomplete" . into ( ) ,
8787 } ) ) ,
88+ is_async : false ,
8889 } ,
8990 & imports,
9091 ) ) ;
@@ -187,6 +188,10 @@ fn function_stubs(function: &Function, imports: &Imports) -> String {
187188 imports. serialize_expr ( decorator, & mut buffer) ;
188189 buffer. push ( '\n' ) ;
189190 }
191+ if function. is_async {
192+ buffer. push_str ( "async " ) ;
193+ }
194+
190195 buffer. push_str ( "def " ) ;
191196 buffer. push_str ( & function. name ) ;
192197 buffer. push ( '(' ) ;
@@ -633,6 +638,7 @@ mod tests {
633638 } ) ,
634639 } ,
635640 returns : Some ( TypeHint :: Plain ( "list[str]" . into ( ) ) ) ,
641+ is_async : false ,
636642 } ;
637643 assert_eq ! (
638644 "def func(posonly, /, arg, *varargs, karg: str, **kwarg: str) -> list[str]: ..." ,
@@ -665,13 +671,35 @@ mod tests {
665671 kwarg : None ,
666672 } ,
667673 returns : None ,
674+ is_async : false ,
668675 } ;
669676 assert_eq ! (
670677 "def afunc(posonly=1, /, arg=True, *, karg: str = \" foo\" ): ..." ,
671678 function_stubs( & function, & Imports :: default ( ) )
672679 )
673680 }
674681
682+ #[ test]
683+ fn test_function_async ( ) {
684+ let function = Function {
685+ name : "foo" . into ( ) ,
686+ decorators : Vec :: new ( ) ,
687+ arguments : Arguments {
688+ positional_only_arguments : Vec :: new ( ) ,
689+ arguments : Vec :: new ( ) ,
690+ vararg : None ,
691+ keyword_only_arguments : Vec :: new ( ) ,
692+ kwarg : None ,
693+ } ,
694+ returns : None ,
695+ is_async : true ,
696+ } ;
697+ assert_eq ! (
698+ "async def foo(): ..." ,
699+ function_stubs( & function, & Imports :: default ( ) )
700+ )
701+ }
702+
675703 #[ test]
676704 fn test_import ( ) {
677705 let big_type = Expr :: Subscript {
@@ -776,6 +804,7 @@ mod tests {
776804 kwarg: None ,
777805 } ,
778806 returns: Some ( TypeHint :: Ast ( big_type. clone( ) ) ) ,
807+ is_async: false ,
779808 } ] ,
780809 attributes : Vec :: new ( ) ,
781810 incomplete : true ,
0 commit comments