@@ -28,29 +28,6 @@ def _has_attr_section(el: dc.Docstring | None):
28
28
return any ([isinstance (x , ds .DocstringSectionAttributes ) for x in el .parsed ])
29
29
30
30
31
- def with_doc_options (f ):
32
- """Decorator to add docstring options to a renderer.
33
-
34
- Currently, the renderer renders signatures directly from griffe objects,
35
- so this decorator is used, to temporarily set some things from layout.Doc
36
- as renderer settings.
37
-
38
- (Not ideal but works for now.)
39
- """
40
-
41
- @wraps (f )
42
- def wrapper (self , el , * args , ** kwargs ):
43
- orig = self .display_name
44
- self .display_name = el .signature_path
45
- res = f (self , el , * args , ** kwargs )
46
-
47
- self .display_name = orig
48
-
49
- return res
50
-
51
- return wrapper
52
-
53
-
54
31
class MdRenderer (Renderer ):
55
32
"""Render docstrings to markdown.
56
33
@@ -152,6 +129,22 @@ def render_annotation(self, el: "str | expr.Name | expr.Expression | None"):
152
129
153
130
# signature method --------------------------------------------------------
154
131
132
+ @dispatch
133
+ def signature (self , el : layout .Doc ):
134
+ orig = self .display_name
135
+
136
+ # set signature path, generate signature, then set back
137
+ # TODO: this is for backwards compatibility with the old approach
138
+ # of only defining signature over griffe objects, which projects
139
+ # like shiny currently extend
140
+ self .display_name = el .signature_path
141
+ res = self .signature (el .obj )
142
+ self .display_name = orig
143
+
144
+ return res
145
+
146
+
147
+
155
148
@dispatch
156
149
def signature (self , el : dc .Alias , source : Optional [dc .Alias ] = None ):
157
150
"""Return a string representation of an object's signature."""
@@ -270,7 +263,6 @@ def render(self, el: layout.Doc):
270
263
raise NotImplementedError (f"Unsupported Doc type: { type (el )} " )
271
264
272
265
@dispatch
273
- @with_doc_options
274
266
def render (self , el : Union [layout .DocClass , layout .DocModule ]):
275
267
title = self .render_header (el )
276
268
@@ -335,30 +327,30 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
335
327
[self .render (x ) for x in raw_meths if isinstance (x , layout .Doc )]
336
328
)
337
329
330
+
331
+ str_sig = self .signature (el )
332
+ sig_part = [str_sig ] if self .show_signature else []
333
+
338
334
body = self .render (el .obj )
339
- return "\n \n " .join ([title , body , * attr_docs , * class_docs , * meth_docs ])
340
335
341
- @dispatch
342
- @with_doc_options
343
- def render (self , el : layout .DocFunction ):
344
- title = self .render_header (el )
345
336
346
- return "\n \n " .join ([title , self . render ( el . obj ) ])
337
+ return "\n \n " .join ([title , * sig_part , body , * attr_docs , * class_docs , * meth_docs ])
347
338
348
339
@dispatch
349
- @with_doc_options
350
- def render (self , el : layout .DocAttribute ):
340
+ def render (self , el : Union [layout .DocFunction , layout .DocAttribute ]):
351
341
title = self .render_header (el )
352
- return "\n \n " .join ([title , self .render (el .obj )])
342
+
343
+ str_sig = self .signature (el )
344
+ sig_part = [str_sig ] if self .show_signature else []
345
+
346
+ return "\n \n " .join ([title , * sig_part , self .render (el .obj )])
353
347
354
348
# render griffe objects ===================================================
355
349
356
350
@dispatch
357
351
def render (self , el : Union [dc .Object , dc .Alias ]):
358
352
"""Render high level objects representing functions, classes, etc.."""
359
353
360
- str_sig = self .signature (el )
361
-
362
354
str_body = []
363
355
if el .docstring is None :
364
356
pass
@@ -374,10 +366,7 @@ def render(self, el: Union[dc.Object, dc.Alias]):
374
366
else :
375
367
str_body .append (body )
376
368
377
- if self .show_signature :
378
- parts = [str_sig , * str_body ]
379
- else :
380
- parts = [* str_body ]
369
+ parts = [* str_body ]
381
370
382
371
return "\n \n " .join (parts )
383
372
0 commit comments