From 736a2b5e729d25bb184db8d42f2ad01025a5bc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 21 Aug 2023 16:50:56 +0200 Subject: [PATCH] refactor: Return anchors as a tuple, not a set, to preserve order Related-to #mkdocstrings/crystal#6: https://github.com/mkdocstrings/crystal/pull/6 --- src/mkdocstrings_handlers/python/handler.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 5fe7668..7b3a8a5 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -357,11 +357,17 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore self.env.filters["get_template"] = rendering.do_get_template self.env.tests["existing_template"] = lambda template_name: template_name in self.env.list_templates() - def get_anchors(self, data: CollectorItem) -> set[str]: # noqa: D102 (ignore missing docstring) + def get_anchors(self, data: CollectorItem) -> tuple[str, ...]: # noqa: D102 (ignore missing docstring) + anchors = [data.path] try: - return {data.path, data.canonical_path, *data.aliases} + if data.canonical_path != data.path: + anchors.append(data.canonical_path) + for anchor in data.aliases: + if anchor not in anchors: + anchors.append(anchor) except AliasResolutionError: - return {data.path} + return tuple(anchors) + return tuple(anchors) def get_handler(