From 548635aa561bd9289019ceb33f7cf73f96c485f9 Mon Sep 17 00:00:00 2001 From: xqt Date: Mon, 2 Dec 2024 16:48:22 +0100 Subject: [PATCH] doc: adjust classproperty docstrings for Python 3.12 and below Bug: T381279 Change-Id: I22706940b1fc4f8ab401313495ff923cc6e9a634 --- pywikibot/tools/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index 7375d0de65..d36f52c092 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -180,11 +180,19 @@ def __init__(self, cls_method) -> None: """Initializer: hold the class method and documentation.""" self.method = cls_method self.__annotations__ = self.method.__annotations__ - self.__doc__ = (':class:`classproperty` ' - f'{self.method.__doc__}') + doc = self.method.__doc__ + self.__doc__ = f':class:`classproperty` {doc}' + rtype = self.__annotations__.get('return') if rtype: - self.__doc__ += f'\n\n:rtype: {rtype}' + lines = doc.splitlines() + + if len(lines) > 2 and PYTHON_VERSION < (3, 13): + spaces = ' ' * re.search('[^ ]', lines[2]).start() + else: + spaces = '' + + self.__doc__ += f'\n{spaces}:rtype: {rtype}' def __get__(self, instance, owner): """Get the attribute of the owner class by its method."""