1
1
import re
2
2
from textwrap import dedent
3
- from typing import Dict , List , Union
3
+ from typing import List
4
4
5
5
# All possible sections in Google style docstrings
6
6
SECTION_HEADERS : List [str ] = [
@@ -68,6 +68,7 @@ def _parse(self, content: str) -> None:
68
68
# Format section
69
69
for part in parts :
70
70
indentation = ""
71
+ skip_first = False
71
72
72
73
if ":" in part [0 ]:
73
74
spl = part [0 ].split (":" )
@@ -76,11 +77,21 @@ def _parse(self, content: str) -> None:
76
77
description = ":" .join (spl [1 :]).lstrip ()
77
78
indentation = (len (arg ) + 6 ) * " "
78
79
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 )
80
85
else :
81
86
self .content += "- {}\n " .format (part [0 ])
82
87
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
+
84
95
self .content += "{}{}\n " .format (indentation , line .lstrip ())
85
96
86
97
self .content = self .content .rstrip ("\n " )
@@ -89,7 +100,6 @@ def as_markdown(self) -> str:
89
100
return "#### {}\n \n {}\n \n " .format (self .name , self .content )
90
101
91
102
92
-
93
103
class GoogleDocstring :
94
104
def __init__ (self , docstring : str ) -> None :
95
105
self .sections : list [Section ] = []
0 commit comments