@@ -381,7 +381,11 @@ def __str__(self) -> str:
381
381
r"""
382
382
^(\*?\*?'?"? # Optional * to allow *args, **kwargs and quotes
383
383
\w[\w.'"]*? # words, dots and closing quotes
384
- (?:[ ]?[\(\]][\(\[\w.\)\]]*?)? # maybe a space and some words in parens.
384
+ (?: # non capturing
385
+ [ ]? # maybe a space
386
+ \( # a `(`
387
+ [\ \(\[\w.,\)\]]*? # word chars, dots or more open/close or space
388
+ )? # all optional
385
389
)\s*:\s # Allow any whitespace around the colon.""" ,
386
390
re .MULTILINE | re .VERBOSE ,
387
391
)
@@ -447,11 +451,26 @@ def split_string(cls, docstring: str):
447
451
text = split .pop (0 )
448
452
items = _pairs (split )
449
453
454
+ items = list (cls ._split_items (items ))
455
+
450
456
title_block = cls (title = title , text = text , items = items )
451
457
parts .append (title_block )
452
458
453
459
return parts
454
460
461
+ @classmethod
462
+ def _split_items (
463
+ cls , items : Iterable [Tuple [str , str ]]
464
+ ) -> Iterable [Tuple [str , str ]]:
465
+ """If there's a type in the name, move it to the top of the description."""
466
+ for name , value in items :
467
+ if '(' in name :
468
+ name , type_str = re .split (r' ?[\(]' , name , maxsplit = 1 )
469
+ type_str = f"`{ type_str .rstrip (')' )} `"
470
+ value = f'{ type_str } \n \n { value } '
471
+
472
+ yield name , value
473
+
455
474
456
475
class DocstringInfo (typing .NamedTuple ):
457
476
brief : str
0 commit comments