Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc issue where parameters listed twice in description #916

Merged
merged 8 commits into from Mar 26, 2022
25 changes: 23 additions & 2 deletions doc/conf.py
Expand Up @@ -40,14 +40,14 @@ def setup(app):
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx_autodoc_typehints",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"cadquery.cq_directive",
"sphinx.ext.mathjax",
]

always_document_param_types = True
autodoc_typehints = "both"
autodoc_typehints_description_target = "all"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down Expand Up @@ -288,3 +288,24 @@ def setup(app):

# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'


def process_docstring_insert_self(app, what, name, obj, options, lines):
"""
Insert self in front of documented params for instance methods
"""

if (
what == "method"
and getattr(obj, "__self__", None) is None
and "self" in obj.__annotations__
):
for i, dstr in enumerate(lines):
if dstr.startswith(":param"):
lines.insert(i, ":param self:")
break


def setup(app):

app.connect("autodoc-process-docstring", process_docstring_insert_self)
3 changes: 1 addition & 2 deletions environment.yml
Expand Up @@ -8,9 +8,8 @@ dependencies:
- ipython
- ocp=7.5.1
- pyparsing>=2.1.9
- sphinx=3.2.1
- sphinx=4.3.0
- sphinx_rtd_theme
- sphinx-autodoc-typehints
- black=19.10b0
- mypy
- codecov
Expand Down