@@ -30,16 +30,28 @@ def tuple_to_data(el: "tuple[ds.DocstringSectionKind, str]"):
30
30
31
31
def docstring_section_narrow (el : ds .DocstringSection ) -> ds .DocstringSection :
32
32
# attempt to narrow down text sections
33
+ to_narrow = [
34
+ DocstringSectionSeeAlso ,
35
+ DocstringSectionNotes ,
36
+ DocstringSectionWarnings ,
37
+ ]
33
38
prefix = "See Also\n ---"
34
- if isinstance (el , ds .DocstringSectionText ) and el .value .startswith (prefix ):
35
- stripped = el .value .replace (prefix , "" , 1 ).lstrip ("-\n " )
36
- return DocstringSectionSeeAlso (stripped , el .title )
39
+
40
+ if isinstance (el , ds .DocstringSectionText ):
41
+ for cls in to_narrow :
42
+ prefix = cls .kind .value .title () + "\n ---"
43
+ if el .value .lstrip ("\n " ).startswith (prefix ):
44
+
45
+ stripped = el .value .replace (prefix , "" , 1 ).lstrip ("-\n " )
46
+ return cls (stripped , el .title )
37
47
38
48
return el
39
49
40
50
41
51
class DocstringSectionKindPatched (Enum ):
42
52
see_also = "see also"
53
+ notes = "notes"
54
+ warnings = "warnings"
43
55
44
56
45
57
class DocstringSectionSeeAlso (ds .DocstringSection ):
@@ -50,6 +62,22 @@ def __init__(self, value: str, title: "str | None"):
50
62
super ().__init__ (title )
51
63
52
64
65
+ class DocstringSectionNotes (ds .DocstringSection ):
66
+ kind = DocstringSectionKindPatched .notes
67
+
68
+ def __init__ (self , value : str , title : "str | None" ):
69
+ self .value = value
70
+ super ().__init__ (title )
71
+
72
+
73
+ class DocstringSectionWarnings (ds .DocstringSection ):
74
+ kind = DocstringSectionKindPatched .warnings
75
+
76
+ def __init__ (self , value : str , title : "str | None" ):
77
+ self .value = value
78
+ super ().__init__ (title )
79
+
80
+
53
81
@dataclass
54
82
class ExampleCode :
55
83
value : str
0 commit comments