Skip to content

Commit 7b44cd2

Browse files
committed
fix: compatibility with griffe 0.39
1 parent 6781777 commit 7b44cd2

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

quartodoc/ast.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from griffe.docstrings import dataclasses as ds
88
from griffe import dataclasses as dc
99
from plum import dispatch
10-
from typing import Union
10+
from typing import Type, Union
1111

1212
from ._pydantic_compat import BaseModel # for previewing
1313

@@ -44,7 +44,7 @@ class DocstringSectionKindPatched(Enum):
4444

4545

4646
class _DocstringSectionPatched(ds.DocstringSection):
47-
_registry: "dict[Enum, _DocstringSectionPatched]" = {}
47+
_registry: "dict[str, Type[_DocstringSectionPatched]]" = {}
4848

4949
def __init__(self, value: str, title: "str | None" = None):
5050
super().__init__(title)
@@ -102,18 +102,27 @@ def transform(cls, el: ds.DocstringSection) -> list[ds.DocstringSection]:
102102
class represents a section like See Also, etc..
103103
"""
104104

105-
if not isinstance(el, ds.DocstringSectionText):
105+
if not isinstance(el, (ds.DocstringSectionText, ds.DocstringSectionAdmonition)):
106106
return [el]
107107

108-
splits = cls.split_sections(el.value)
109108
results = []
110-
for title, body in splits:
111-
sub_cls = cls._registry.get(title.lower(), ds.DocstringSectionText)
112109

113-
# note that griffe currently doesn't store the title anywhere,
114-
# but we add the exact title here, so we can be flexible about the
115-
# sections we parse (e.g. Note instead of Notes) in the future.
116-
results.append(sub_cls(body, title))
110+
if isinstance(el, ds.DocstringSectionText):
111+
# griffe < 0.39
112+
splits = cls.split_sections(el.value)
113+
for title, body in splits:
114+
sub_cls = cls._registry.get(title.lower(), ds.DocstringSectionText)
115+
116+
# note that griffe currently doesn't store the title anywhere,
117+
# but we add the exact title here, so we can be flexible about the
118+
# sections we parse (e.g. Note instead of Notes) in the future.
119+
results.append(sub_cls(body, title))
120+
elif isinstance(el, ds.DocstringSectionAdmonition):
121+
sub_cls = cls._registry.get(el.title.lower(), None)
122+
if sub_cls:
123+
results.append(sub_cls(el.value.contents, el.title))
124+
else:
125+
results.append(el)
117126

118127
return results or [el]
119128

0 commit comments

Comments
 (0)