@@ -60,7 +60,7 @@ class Section(_Base):
60
60
title : str
61
61
desc : str
62
62
package : Union [str , None , MISSING ] = MISSING ()
63
- contents : list [ Union [ ContentElement , Doc , _AutoDefault ]]
63
+ contents : ContentList
64
64
65
65
66
66
class SummaryDetails (_Base ):
@@ -79,7 +79,7 @@ class Page(_Base):
79
79
summary : Optional [SummaryDetails ] = None
80
80
flatten : bool = False
81
81
82
- contents : list [ Union [ ContentElement , Doc , _AutoDefault ]]
82
+ contents : ContentList
83
83
84
84
@property
85
85
def obj (self ):
@@ -99,6 +99,32 @@ class MemberPage(Page):
99
99
contents : list [Doc ]
100
100
101
101
102
+ class Interlaced (BaseModel ):
103
+ """A group of objects, whose documentation will be interlaced.
104
+
105
+ Rather than list each object's documentation in sequence, this element indicates
106
+ that each piece of documentation (e.g. signatures, examples) should be grouped
107
+ together.
108
+ """
109
+
110
+ kind : Literal ["interlaced" ] = "interlaced"
111
+ package : Union [str , None , MISSING ] = MISSING ()
112
+
113
+ # note that this is similar to a ContentList, except it cannot include
114
+ # elements like Pages, etc..
115
+ contents : list [Union [Auto , Doc , _AutoDefault ]]
116
+
117
+ @property
118
+ def name (self ):
119
+ if not self .contents :
120
+ raise AttributeError (
121
+ f"Cannot get property name for object of type { type (self )} ."
122
+ " There are no content elements."
123
+ )
124
+
125
+ return self .contents [0 ].name
126
+
127
+
102
128
class Text (_Base ):
103
129
kind : Literal ["text" ] = "text"
104
130
contents : str
@@ -180,7 +206,12 @@ class Config:
180
206
181
207
@classmethod
182
208
def from_griffe (
183
- cls , name , obj : Union [dc .Object , dc .Alias ], members = None , anchor : str = None
209
+ cls ,
210
+ name ,
211
+ obj : Union [dc .Object , dc .Alias ],
212
+ members = None ,
213
+ anchor : str = None ,
214
+ flat : bool = False ,
184
215
):
185
216
if members is None :
186
217
members = []
@@ -195,9 +226,9 @@ def from_griffe(
195
226
elif kind == "attribute" :
196
227
return DocAttribute (** kwargs )
197
228
elif kind == "class" :
198
- return DocClass (members = members , ** kwargs )
229
+ return DocClass (members = members , flat = flat , ** kwargs )
199
230
elif kind == "module" :
200
- return DocModule (members = members , ** kwargs )
231
+ return DocModule (members = members , flat = flat , ** kwargs )
201
232
202
233
raise TypeError (f"Cannot handle auto for object kind: { obj .kind } " )
203
234
@@ -209,6 +240,7 @@ class DocFunction(Doc):
209
240
class DocClass (Doc ):
210
241
kind : Literal ["class" ] = "class"
211
242
members : list [Union [MemberPage , Doc , Link ]] = tuple ()
243
+ flat : bool
212
244
213
245
214
246
class DocAttribute (Doc ):
@@ -218,16 +250,19 @@ class DocAttribute(Doc):
218
250
class DocModule (Doc ):
219
251
kind : Literal ["module" ] = "module"
220
252
members : list [Union [MemberPage , Doc , Link ]] = tuple ()
253
+ flat : bool
221
254
222
255
223
256
SectionElement = Annotated [Union [Section , Page ], Field (discriminator = "kind" )]
224
257
"""Entry in the sections list."""
225
258
226
259
ContentElement = Annotated [
227
- Union [Page , Section , Text , Auto ], Field (discriminator = "kind" )
260
+ Union [Page , Section , Interlaced , Text , Auto ], Field (discriminator = "kind" )
228
261
]
229
262
"""Entry in the contents list."""
230
263
264
+ ContentList = list [Union [ContentElement , Doc , _AutoDefault ]]
265
+
231
266
# Item ----
232
267
233
268
@@ -248,3 +283,4 @@ class Config:
248
283
Page .update_forward_refs ()
249
284
Auto .update_forward_refs ()
250
285
MemberPage .update_forward_refs ()
286
+ Interlaced .update_forward_refs ()
0 commit comments