Skip to content

Commit

Permalink
doc: adjust classproperty docstrings for Python 3.12 and below
Browse files Browse the repository at this point in the history
Bug: T381279
Change-Id: I22706940b1fc4f8ab401313495ff923cc6e9a634
  • Loading branch information
xqt committed Dec 2, 2024
1 parent bf2c1c7 commit 548635a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pywikibot/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<tools.classproperty>` '
f'{self.method.__doc__}')
doc = self.method.__doc__
self.__doc__ = f':class:`classproperty<tools.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."""
Expand Down

0 comments on commit 548635a

Please sign in to comment.