@@ -91,6 +91,7 @@ pub struct PyFunctionOptions {
9191 pub signature : Option < SignatureAttribute > ,
9292 pub text_signature : Option < TextSignatureAttribute > ,
9393 pub krate : Option < CrateAttribute > ,
94+ pub allow_threads : Option < attributes:: kw:: allow_threads > ,
9495}
9596
9697impl Parse for PyFunctionOptions {
@@ -99,7 +100,8 @@ impl Parse for PyFunctionOptions {
99100
100101 while !input. is_empty ( ) {
101102 let lookahead = input. lookahead1 ( ) ;
102- if lookahead. peek ( attributes:: kw:: name)
103+ if lookahead. peek ( attributes:: kw:: allow_threads)
104+ || lookahead. peek ( attributes:: kw:: name)
103105 || lookahead. peek ( attributes:: kw:: pass_module)
104106 || lookahead. peek ( attributes:: kw:: signature)
105107 || lookahead. peek ( attributes:: kw:: text_signature)
@@ -121,6 +123,7 @@ impl Parse for PyFunctionOptions {
121123}
122124
123125pub enum PyFunctionOption {
126+ AllowThreads ( attributes:: kw:: allow_threads ) ,
124127 Name ( NameAttribute ) ,
125128 PassModule ( attributes:: kw:: pass_module ) ,
126129 Signature ( SignatureAttribute ) ,
@@ -131,7 +134,9 @@ pub enum PyFunctionOption {
131134impl Parse for PyFunctionOption {
132135 fn parse ( input : ParseStream < ' _ > ) -> Result < Self > {
133136 let lookahead = input. lookahead1 ( ) ;
134- if lookahead. peek ( attributes:: kw:: name) {
137+ if lookahead. peek ( attributes:: kw:: allow_threads) {
138+ input. parse ( ) . map ( PyFunctionOption :: AllowThreads )
139+ } else if lookahead. peek ( attributes:: kw:: name) {
135140 input. parse ( ) . map ( PyFunctionOption :: Name )
136141 } else if lookahead. peek ( attributes:: kw:: pass_module) {
137142 input. parse ( ) . map ( PyFunctionOption :: PassModule )
@@ -171,6 +176,7 @@ impl PyFunctionOptions {
171176 }
172177 for attr in attrs {
173178 match attr {
179+ PyFunctionOption :: AllowThreads ( allow_threads) => set_option ! ( allow_threads) ,
174180 PyFunctionOption :: Name ( name) => set_option ! ( name) ,
175181 PyFunctionOption :: PassModule ( pass_module) => set_option ! ( pass_module) ,
176182 PyFunctionOption :: Signature ( signature) => set_option ! ( signature) ,
@@ -198,6 +204,7 @@ pub fn impl_wrap_pyfunction(
198204) -> syn:: Result < TokenStream > {
199205 check_generic ( & func. sig ) ?;
200206 let PyFunctionOptions {
207+ allow_threads,
201208 pass_module,
202209 name,
203210 signature,
@@ -247,6 +254,7 @@ pub fn impl_wrap_pyfunction(
247254 signature,
248255 output : ty,
249256 text_signature,
257+ allow_threads,
250258 asyncness : func. sig . asyncness ,
251259 unsafety : func. sig . unsafety ,
252260 deprecations : Deprecations :: new ( ) ,
0 commit comments