Skip to content

Commit 84aaebc

Browse files
committed
feat: Release __all__ ordering feature
1 parent 3be14cc commit 84aaebc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/mkdocstrings_handlers/python/_internal/rendering.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ def _sort_key_source(item: CollectorItem) -> float:
6262
return item.lineno if item.lineno is not None else float("inf")
6363

6464

65-
def _sort__all__(item: CollectorItem) -> float: # noqa: ARG001
66-
raise ValueError("Not implemented in public version of mkdocstrings-python")
65+
def _sort__all__(item: CollectorItem) -> float:
66+
if item.parent.exports is not None:
67+
try:
68+
return item.parent.exports.index(item.name)
69+
except ValueError:
70+
# If the item is not in `__all__`, it will go to the end of the list.
71+
return float("inf")
72+
# No exports declared, refuse to sort (try other methods or return members as they are).
73+
raise ValueError(f"Parent object {item.parent.path} doesn't declare exports")
6774

6875

6976
Order = Literal["__all__", "alphabetical", "source"]

0 commit comments

Comments
 (0)