11import re
22from textwrap import dedent
3- from typing import Dict , List , Union
3+ from typing import List
44
55# All possible sections in Google style docstrings
66SECTION_HEADERS : List [str ] = [
@@ -68,6 +68,7 @@ def _parse(self, content: str) -> None:
6868 # Format section
6969 for part in parts :
7070 indentation = ""
71+ skip_first = False
7172
7273 if ":" in part [0 ]:
7374 spl = part [0 ].split (":" )
@@ -76,11 +77,21 @@ def _parse(self, content: str) -> None:
7677 description = ":" .join (spl [1 :]).lstrip ()
7778 indentation = (len (arg ) + 6 ) * " "
7879
79- self .content += "- `{}`: {}\n " .format (arg , description )
80+ if description :
81+ self .content += "- `{}`: {}\n " .format (arg , description )
82+ else :
83+ skip_first = True
84+ self .content += "- `{}`: " .format (arg )
8085 else :
8186 self .content += "- {}\n " .format (part [0 ])
8287
83- for line in part [1 :]:
88+ for n , line in enumerate (part [1 :]):
89+ if skip_first and n == 0 :
90+ # This ensures that indented args get moved to the
91+ # previous line
92+ self .content += "{}\n " .format (line .lstrip ())
93+ continue
94+
8495 self .content += "{}{}\n " .format (indentation , line .lstrip ())
8596
8697 self .content = self .content .rstrip ("\n " )
@@ -89,7 +100,6 @@ def as_markdown(self) -> str:
89100 return "#### {}\n \n {}\n \n " .format (self .name , self .content )
90101
91102
92-
93103class GoogleDocstring :
94104 def __init__ (self , docstring : str ) -> None :
95105 self .sections : list [Section ] = []
0 commit comments