Skip to content

Commit

Permalink
Fix property getter annotations
Browse files Browse the repository at this point in the history
- Sphinx doesn't parse pybind11's property annotations
  • Loading branch information
virtuald committed Dec 12, 2023
1 parent 2c360af commit cbb64ea
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions robotpy_sphinx/pybind11_fixer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
from typing import Optional, Tuple


Expand All @@ -10,6 +11,21 @@ def process_signature(
signature: Optional[str],
return_annotation: Optional[str],
) -> Optional[Tuple[str, Optional[str]]]:
# sphinx completely ignores pybind11 property annotations, so fix them
if what == "property":
# If sphinx figured it out, no need to override it
if signature:
return signature, return_annotation

if hasattr(obj, "fget"):
fdoc = inspect.getdoc(obj.fget)
if fdoc and fdoc.startswith("(self:"):
s = fdoc.split("->")
if len(s) == 2:
return "(self)", s[1]

return

if what not in ("class", "method") or signature is None:
return

Expand Down

0 comments on commit cbb64ea

Please sign in to comment.