@@ -340,7 +340,6 @@ fn impl_py_class(attr: AttributeArgs, item: Item) -> TokenStream2 {
340
340
} ;
341
341
let rp_path = rustpython_path_attr ( & attr) ;
342
342
let mut class_name = None ;
343
- let mut doc = None ;
344
343
for attr in attr {
345
344
if let NestedMeta :: Meta ( meta) = attr {
346
345
if let Meta :: NameValue ( name_value) = meta {
@@ -350,19 +349,35 @@ fn impl_py_class(attr: AttributeArgs, item: Item) -> TokenStream2 {
350
349
} else {
351
350
panic ! ( "#[py_class(name = ...)] must be a string" ) ;
352
351
}
353
- } else if name_value. ident == "doc" {
354
- if let Lit :: Str ( s) = name_value. lit {
355
- doc = Some ( s. value ( ) ) ;
356
- } else {
357
- panic ! ( "#[py_class(name = ...)] must be a string" ) ;
358
- }
359
352
}
360
353
}
361
354
}
362
355
}
363
356
let class_name = class_name. expect ( "#[py_class] must have a name" ) ;
357
+ let mut doc: Option < Vec < String > > = None ;
358
+ for attr in imp. attrs . iter ( ) {
359
+ if attr. path . is_ident ( "doc" ) {
360
+ let meta = attr. parse_meta ( ) . expect ( "expected doc attr to be a meta" ) ;
361
+ if let Meta :: NameValue ( name_value) = meta {
362
+ if let Lit :: Str ( s) = name_value. lit {
363
+ let val = s. value ( ) . trim ( ) . to_string ( ) ;
364
+ match doc {
365
+ Some ( ref mut doc) => doc. push ( val) ,
366
+ None => doc = Some ( vec ! [ val] ) ,
367
+ }
368
+ } else {
369
+ panic ! ( "expected #[doc = ...] to be a string" )
370
+ }
371
+ } else {
372
+ panic ! ( "expected #[doc] to be a NameValue, e.g. #[doc = \" ...\" " ) ;
373
+ }
374
+ }
375
+ }
364
376
let doc = match doc {
365
- Some ( doc) => quote ! ( Some ( #doc) ) ,
377
+ Some ( doc) => {
378
+ let doc = doc. join ( "\n " ) ;
379
+ quote ! ( Some ( #doc) )
380
+ }
366
381
None => quote ! ( None ) ,
367
382
} ;
368
383
let ty = & imp. self_ty ;
0 commit comments