Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
DOC: Add __init__ documentation to class documentation
Browse files Browse the repository at this point in the history
Add `__init__` documentation to class documentation:
- Add a function to the documentation configuration file that processes
  the signatures and adds the `__init__` method signature to the class
  signatures.
- Make the class documentation contain the documentation from both the
  class and the `__ini__` method setting the `autoclass_content` option
  to `both`.

Remove the short description of the `__init__` methods so that the class
documentation reads seamlessly.
  • Loading branch information
jhlegarreta committed Dec 8, 2024
1 parent f10fc12 commit 5d10d90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 27 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
apidoc_separate_modules = True
apidoc_extra_args = ["--module-first", "-d 1", "-T"]


# -- Options for autodoc extension -------------------------------------------
autoclass_content = "both"


# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
Expand All @@ -253,3 +258,25 @@

# -- Options for versioning extension ----------------------------------------
scv_show_banner = True


# -- Special functions -------------------------------------------------------
import inspect


def autodoc_process_signature(app, what, name, obj, options, signature, return_annotation):
"""Replace the class signature by the signature from cls.__init__"""

if what == "class" and hasattr(obj, "__init__"):
try:
init_signature = inspect.signature(obj.__init__)
# Convert the Signature object to a string
return str(init_signature), return_annotation
except ValueError:
# Handle cases where `inspect.signature` fails
return signature, return_annotation
return signature, return_annotation


def setup(app):
app.connect("autodoc-process-signature", autodoc_process_signature)
2 changes: 0 additions & 2 deletions src/eddymotion/model/gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def __init__(
l_bounds: tuple[float, float] = BOUNDS_LAMBDA,
):
r"""
Initialize an exponential Kriging kernel.
Parameters
----------
Expand Down Expand Up @@ -370,7 +369,6 @@ def __init__(
l_bounds: tuple[float, float] = BOUNDS_LAMBDA,
):
r"""
Initialize a spherical Kriging kernel.
Parameters
----------
Expand Down

0 comments on commit 5d10d90

Please sign in to comment.