2
2
from textwrap import dedent
3
3
from typing import Dict , List , Union
4
4
5
- _GOOGLE_SECTIONS : List [str ] = [
5
+ # All possible sections in Google style docstrings
6
+ SECTION_HEADERS : List [str ] = [
6
7
"Args" ,
7
8
"Returns" ,
8
9
"Raises" ,
14
15
"Todo" ,
15
16
]
16
17
18
+ # These sections will not be parsed as a list of arguments/return values/etc
19
+ PLAIN_TEXT_SECTIONS : List [str ] = [
20
+ "Examples" ,
21
+ "Example" ,
22
+ "Note" ,
23
+ "Todo" ,
24
+ ]
25
+
17
26
ESCAPE_RULES = {
18
27
# Avoid Markdown in magic methods or filenames like __init__.py
19
28
r"__(?P<text>\S+)__" : r"\_\_\g<text>\_\_" ,
@@ -30,6 +39,10 @@ def __init__(self, name: str, content: str) -> None:
30
39
def _parse (self , content : str ) -> None :
31
40
content = content .rstrip ("\n " )
32
41
42
+ if self .name in PLAIN_TEXT_SECTIONS :
43
+ self .content = dedent (content )
44
+ return
45
+
33
46
parts = []
34
47
cur_part = []
35
48
@@ -125,15 +138,15 @@ def as_markdown(self) -> str:
125
138
126
139
127
140
def is_section (line : str ) -> bool :
128
- for section in _GOOGLE_SECTIONS :
141
+ for section in SECTION_HEADERS :
129
142
if re .search (r"{}:" .format (section ), line ):
130
143
return True
131
144
132
145
return False
133
146
134
147
135
148
def looks_like_google (value : str ) -> bool :
136
- for section in _GOOGLE_SECTIONS :
149
+ for section in SECTION_HEADERS :
137
150
if re .search (r"{}:\n" .format (section ), value ):
138
151
return True
139
152
0 commit comments