Skip to content

Commit

Permalink
make descriptor usage compatibel with Sphinx autodoc
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Mar 23, 2024
1 parent 6ccea45 commit 90a06ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
33 changes: 33 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,36 @@

html_static_path = ["_static"]
html_css_files = ["css/custom.css"]

dummy_object = object()
empty_dict = {}


def hook(_app, what, _name, obj, _options, _lines):
if what != "class":
return

annotations = {}
for cls in reversed(obj.mro()):
cls_annotations = getattr(cls, "__annotations__", empty_dict)

for key, value in cls.__dict__.items():
if key.startswith("_") or not isinstance(value, object):
continue

if key in cls_annotations:
annotations[key] = cls_annotations[key]
else:
getter = getattr(value, "__get__", dummy_object)
return_type = getattr(getter, "__annotations__", empty_dict).get(
"return"
)
if return_type:
annotations[key] = return_type

if cls is obj:
cls_annotations.update(annotations)


def setup(app):
app.connect("autodoc-process-docstring", hook)
2 changes: 1 addition & 1 deletion zammadoo/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def reload(self, expand=False) -> None:
info.update(new_info)

def last_request_at(self) -> Optional[datetime]:
"""return the last request timestamp as :class:`datetime` or ``None``"""
""":return: the last request timestamp as :class:`datetime` or ``None``"""
return self.parent.cached_timestamp(self.id)


Expand Down
1 change: 0 additions & 1 deletion zammadoo/time_accountings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class TimeAccounting(MutableResource):
ticket_id: int #:
ticket_article_id: Optional[int] #:
time_unit: str #:

updated_by = UserProperty("created_by_id")

@property
Expand Down
7 changes: 3 additions & 4 deletions zammadoo/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ class User(NamedResource):
fax: str #:
firstname: str #:
image: Optional[str] #:
last_login = OptionalDateTime()
lastname: str #:
login: str #: users login name
login_failed: int #:
mobile: str #:
out_of_office: bool #:
out_of_office_end_at: Optional[str] #:
out_of_office_start_at: Optional[str] #:
out_of_office_end_at = OptionalDateTime()
out_of_office_start_at = OptionalDateTime()
phone: str #:
verified: bool #:
vip: bool #:
web: str #:

last_login = OptionalDateTime()

@property
def fullname(self) -> str:
"""users firstname and lastname combined, or email"""
Expand Down

0 comments on commit 90a06ef

Please sign in to comment.