@@ -236,21 +236,21 @@ pub fn gen_py_method(
236236 ( _, FnType :: Fn ( _) ) => GeneratedPyMethod :: Method ( impl_py_method_def (
237237 cls,
238238 spec,
239- & spec. get_doc ( meth_attrs, ctx) ,
239+ & spec. get_doc ( meth_attrs, ctx) ? ,
240240 None ,
241241 ctx,
242242 ) ?) ,
243243 ( _, FnType :: FnClass ( _) ) => GeneratedPyMethod :: Method ( impl_py_method_def (
244244 cls,
245245 spec,
246- & spec. get_doc ( meth_attrs, ctx) ,
246+ & spec. get_doc ( meth_attrs, ctx) ? ,
247247 Some ( quote ! ( #pyo3_path:: ffi:: METH_CLASS ) ) ,
248248 ctx,
249249 ) ?) ,
250250 ( _, FnType :: FnStatic ) => GeneratedPyMethod :: Method ( impl_py_method_def (
251251 cls,
252252 spec,
253- & spec. get_doc ( meth_attrs, ctx) ,
253+ & spec. get_doc ( meth_attrs, ctx) ? ,
254254 Some ( quote ! ( #pyo3_path:: ffi:: METH_STATIC ) ) ,
255255 ctx,
256256 ) ?) ,
@@ -264,7 +264,7 @@ pub fn gen_py_method(
264264 PropertyType :: Function {
265265 self_type,
266266 spec,
267- doc : spec. get_doc ( meth_attrs, ctx) ,
267+ doc : spec. get_doc ( meth_attrs, ctx) ? ,
268268 } ,
269269 ctx,
270270 ) ?) ,
@@ -273,7 +273,7 @@ pub fn gen_py_method(
273273 PropertyType :: Function {
274274 self_type,
275275 spec,
276- doc : spec. get_doc ( meth_attrs, ctx) ,
276+ doc : spec. get_doc ( meth_attrs, ctx) ? ,
277277 } ,
278278 ctx,
279279 ) ?) ,
@@ -360,10 +360,14 @@ pub fn impl_py_method_def_new(
360360 // Use just the text_signature_call_signature() because the class' Python name
361361 // isn't known to `#[pymethods]` - that has to be attached at runtime from the PyClassImpl
362362 // trait implementation created by `#[pyclass]`.
363- let text_signature_body = spec. text_signature_call_signature ( ) . map_or_else (
364- || quote ! ( :: std:: option:: Option :: None ) ,
365- |text_signature| quote ! ( :: std:: option:: Option :: Some ( #text_signature) ) ,
366- ) ;
363+ let text_signature_impl = spec. text_signature_call_signature ( ) . map ( |text_signature| {
364+ quote ! {
365+ #[ allow( unknown_lints, non_local_definitions) ]
366+ impl #pyo3_path:: impl_:: pyclass:: doc:: PyClassNewTextSignature for #cls {
367+ const TEXT_SIGNATURE : & ' static str = #text_signature;
368+ }
369+ }
370+ } ) ;
367371 let slot_def = quote ! {
368372 #pyo3_path:: ffi:: PyType_Slot {
369373 slot: #pyo3_path:: ffi:: Py_tp_new ,
@@ -373,13 +377,8 @@ pub fn impl_py_method_def_new(
373377 args: * mut #pyo3_path:: ffi:: PyObject ,
374378 kwargs: * mut #pyo3_path:: ffi:: PyObject ,
375379 ) -> * mut #pyo3_path:: ffi:: PyObject {
376- #[ allow( unknown_lints, non_local_definitions) ]
377- impl #pyo3_path:: impl_:: pyclass:: PyClassNewTextSignature <#cls> for #pyo3_path:: impl_:: pyclass:: PyClassImplCollector <#cls> {
378- #[ inline]
379- fn new_text_signature( self ) -> :: std:: option:: Option <& ' static str > {
380- #text_signature_body
381- }
382- }
380+
381+ #text_signature_impl
383382
384383 #pyo3_path:: impl_:: trampoline:: newfunc(
385384 subtype,
@@ -627,7 +626,7 @@ pub fn impl_py_setter_def(
627626) -> Result < MethodAndMethodDef > {
628627 let Ctx { pyo3_path, .. } = ctx;
629628 let python_name = property_type. null_terminated_python_name ( ctx) ?;
630- let doc = property_type. doc ( ctx) ;
629+ let doc = property_type. doc ( ctx) ? ;
631630 let mut holders = Holders :: new ( ) ;
632631 let setter_impl = match property_type {
633632 PropertyType :: Descriptor {
@@ -815,7 +814,7 @@ pub fn impl_py_getter_def(
815814) -> Result < MethodAndMethodDef > {
816815 let Ctx { pyo3_path, .. } = ctx;
817816 let python_name = property_type. null_terminated_python_name ( ctx) ?;
818- let doc = property_type. doc ( ctx) ;
817+ let doc = property_type. doc ( ctx) ? ;
819818
820819 let mut cfg_attrs = TokenStream :: new ( ) ;
821820 if let PropertyType :: Descriptor { field, .. } = & property_type {
@@ -978,12 +977,12 @@ impl PropertyType<'_> {
978977 }
979978 }
980979
981- fn doc ( & self , ctx : & Ctx ) -> Cow < ' _ , PythonDoc > {
980+ fn doc ( & self , ctx : & Ctx ) -> Result < Cow < ' _ , PythonDoc > > {
982981 match self {
983982 PropertyType :: Descriptor { field, .. } => {
984- Cow :: Owned ( utils:: get_doc ( & field. attrs , None , ctx) )
983+ utils:: get_doc ( & field. attrs , None , ctx) . map ( Cow :: Owned )
985984 }
986- PropertyType :: Function { doc, .. } => Cow :: Borrowed ( doc) ,
985+ PropertyType :: Function { doc, .. } => Ok ( Cow :: Borrowed ( doc) ) ,
987986 }
988987 }
989988}
0 commit comments