From 434855ffdd583205d953bf01cc920f49e39ddf3d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 10 Oct 2023 01:35:37 +0200 Subject: [PATCH] A better logic to process relative references in docstrings. --- platypush/common/reflection/_parser/rst.py | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/platypush/common/reflection/_parser/rst.py b/platypush/common/reflection/_parser/rst.py index 8fcdfcdd4c..93d4d44b68 100644 --- a/platypush/common/reflection/_parser/rst.py +++ b/platypush/common/reflection/_parser/rst.py @@ -3,6 +3,8 @@ import logging import re import textwrap as tw +from platypush.utils import get_defining_class + from .._model.constants import doc_base_url from .context import ParseContext @@ -130,9 +132,13 @@ class RstExtensionsMixin: cls, docstr: str, ex_name: str, match: re.Match, ctx: ParseContext ) -> str: value = match.group("name") + modname = obj_name = url_path = None + if value.startswith("."): - modname = ctx.obj.__module__ # noqa - obj_name = ctx.obj.__qualname__ + base_cls = get_defining_class(ctx.obj) + if base_cls: + modname = base_cls.__module__ + obj_name = f'{base_cls.__qualname__}.{value[1:]}' elif ex_name == "method": modname = ".".join(value.split(".")[:-2]) obj_name = ".".join(value.split(".")[-2:]) @@ -140,16 +146,15 @@ class RstExtensionsMixin: modname = ".".join(value.split(".")[:-1]) obj_name = value.split(".")[-1] - url_path = None - - if modname.startswith("platypush.plugins"): - url_path = "plugins/" + ".".join(modname.split(".")[2:]) - elif modname.startswith("platypush.backend"): - url_path = "backends/" + ".".join(modname.split(".")[2:]) - elif modname.startswith("platypush.message.event"): - url_path = "events/" + ".".join(modname.split(".")[3:]) - elif modname.startswith("platypush.message.response"): - url_path = "responses/" + ".".join(modname.split(".")[3:]) + if modname and obj_name: + if modname.startswith("platypush.plugins"): + url_path = "plugins/" + ".".join(modname.split(".")[2:]) + elif modname.startswith("platypush.backend"): + url_path = "backends/" + ".".join(modname.split(".")[2:]) + elif modname.startswith("platypush.message.event"): + url_path = "events/" + ".".join(modname.split(".")[3:]) + elif modname.startswith("platypush.message.response"): + url_path = "responses/" + ".".join(modname.split(".")[3:]) if url_path: docstr = docstr.replace(