|
1 | 1 | from griffe.docstrings import dataclasses as ds
|
2 | 2 | from griffe import dataclasses as dc
|
| 3 | +from griffe.expressions import Expression, Name |
3 | 4 | from dataclasses import dataclass
|
4 | 5 | from tabulate import tabulate
|
5 | 6 | from plum import dispatch
|
@@ -128,6 +129,15 @@ def __init__(
|
128 | 129 | def to_md(self, el):
|
129 | 130 | raise NotImplementedError(f"Unsupported type: {type(el)}")
|
130 | 131 |
|
| 132 | + @dispatch |
| 133 | + def to_md(self, el: str): |
| 134 | + return el |
| 135 | + |
| 136 | + @dispatch |
| 137 | + def to_md(self, el: Union[Expression, Name]): |
| 138 | + # these are used often for annotations, and full returns it as a string |
| 139 | + return el.full |
| 140 | + |
131 | 141 | @dispatch
|
132 | 142 | def to_md(self, el: Union[dc.Alias, dc.Object]):
|
133 | 143 | # TODO: replace hard-coded header level
|
@@ -204,6 +214,19 @@ def to_md(self, el: ds.DocstringParameter) -> Tuple[str]:
|
204 | 214 | annotation = el.annotation.full if el.annotation else None
|
205 | 215 | return (escape(el.name), annotation, sanitize(el.description), default)
|
206 | 216 |
|
| 217 | + # attributes ---- |
| 218 | + |
| 219 | + @dispatch |
| 220 | + def to_md(self, el: ds.DocstringSectionAttributes): |
| 221 | + header = ["Name", "Type", "Description"] |
| 222 | + rows = list(map(self.to_md, el.value)) |
| 223 | + |
| 224 | + return tabulate(rows, header, tablefmt="github") |
| 225 | + |
| 226 | + @dispatch |
| 227 | + def to_md(self, el: ds.DocstringAttribute): |
| 228 | + return el.name, self.to_md(el.annotation), el.description |
| 229 | + |
207 | 230 | # examples ----
|
208 | 231 |
|
209 | 232 | @dispatch
|
|
0 commit comments