Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1099361?usp=email )

Change subject: doc: Enable docstring with classproperty methods
......................................................................

doc: Enable docstring with classproperty methods

- modify docstring of classproperty methods to show a preleading
  classproperty and add rtype if present.
- return the modified decorator class when Sphinx is running.

Bug: T380628
Change-Id: Ie44c9f89d34e7cf4aec332daf8cbed9b30ac0dc8
---
M pywikibot/tools/__init__.py
1 file changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved




diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 298f095..7375d0d 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -177,12 +177,20 @@
     """

     def __init__(self, cls_method) -> None:
-        """Hold the class method."""
+        """Initializer: hold the class method and documentation."""
         self.method = cls_method
-        self.__doc__ = self.method.__doc__
+        self.__annotations__ = self.method.__annotations__
+        self.__doc__ = (':class:`classproperty<tools.classproperty>` '
+                        f'{self.method.__doc__}')
+        rtype = self.__annotations__.get('return')
+        if rtype:
+            self.__doc__ += f'\n\n:rtype: {rtype}'

     def __get__(self, instance, owner):
         """Get the attribute of the owner class by its method."""
+        if SPHINX_RUNNING:
+            return self
+
         return self.method(owner)



--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1099361?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie44c9f89d34e7cf4aec332daf8cbed9b30ac0dc8
Gerrit-Change-Number: 1099361
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <i...@gno.de>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org

Reply via email to