@@ -381,7 +381,11 @@ def __str__(self) -> str:
381381 r"""
382382 ^(\*?\*?'?"? # Optional * to allow *args, **kwargs and quotes
383383 \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
385389 )\s*:\s # Allow any whitespace around the colon.""" ,
386390 re .MULTILINE | re .VERBOSE ,
387391 )
@@ -447,11 +451,26 @@ def split_string(cls, docstring: str):
447451 text = split .pop (0 )
448452 items = _pairs (split )
449453
454+ items = list (cls ._split_items (items ))
455+
450456 title_block = cls (title = title , text = text , items = items )
451457 parts .append (title_block )
452458
453459 return parts
454460
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+
455474
456475class DocstringInfo (typing .NamedTuple ):
457476 brief : str
0 commit comments