From f9ecbbc6ba9573475b8de1063b593b59e02faa24 Mon Sep 17 00:00:00 2001 From: Liran Funaro Date: Tue, 27 Aug 2024 22:31:35 +0300 Subject: [PATCH] Add support for `autodoc_typehints=signature` Signed-off-by: Liran Funaro --- Makefile | 6 ++- pyproject.toml | 2 +- sphinx_markdown_builder/translator.py | 4 ++ tests/expected/overrides-auto-module.md | 54 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/expected/overrides-auto-module.md diff --git a/Makefile b/Makefile index 2e1fa8e..f4586ce 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,12 @@ test-diff: @echo "Building markdown with configuration overrides..." @$(SPHINX_BUILD) -M markdown "$(SOURCE_DIR)" "$(BUILD_DIR)/overrides" $(SPHINX_OPTS) $(O) -a \ -D markdown_http_base="https://localhost" -D markdown_uri_doc_suffix=".html" \ - -D markdown_docinfo=True -D markdown_anchor_sections=True -D markdown_anchor_signatures=True + -D markdown_docinfo=True -D markdown_anchor_sections=True -D markdown_anchor_signatures=True \ + -D autodoc_typehints=signature - @# Copy just one file for verification + @# Copy just the files for verification @cp "$(BUILD_DIR)/overrides/markdown/auto-summery.md" "$(BUILD_DIR)/markdown/overrides-auto-summery.md" + @cp "$(BUILD_DIR)/overrides/markdown/auto-module.md" "$(BUILD_DIR)/markdown/overrides-auto-module.md" @echo "Verifies outputs..." @diff --recursive --color=always --side-by-side --text --suppress-common-lines \ diff --git a/pyproject.toml b/pyproject.toml index e52736b..2cb63ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ requires-python = ">=3.7" dev = [ "sphinx>=5.3.0", # For development, we need a higher version for the tests' outputs to be identical. "bumpver", "black", "isort", "flake8", "pylint", "pip-tools", "pytest", "pytest-cov", "coveralls", - "sphinx-needs", "sphinxcontrib-plantuml", "sphinxcontrib.httpdomain", + "sphinxcontrib-plantuml", "sphinxcontrib.httpdomain", ] [project.urls] diff --git a/sphinx_markdown_builder/translator.py b/sphinx_markdown_builder/translator.py index 8a8901b..7add997 100644 --- a/sphinx_markdown_builder/translator.py +++ b/sphinx_markdown_builder/translator.py @@ -599,6 +599,7 @@ def visit_bullet_list(self, node): # desc_parameterlist # desc_annotation # desc_parameter + # desc_returns # desc_content # field_list # field @@ -652,6 +653,9 @@ def visit_field_list(self, _node): visit_field = _start_list_item depart_field = _end_list_item + def visit_desc_returns(self, _node): + self.add(" → ") + @pushing_context def visit_field_body(self, _node): self._push_context(SubContext(SubContextParams(1, 1))) diff --git a/tests/expected/overrides-auto-module.md b/tests/expected/overrides-auto-module.md new file mode 100644 index 0000000..18cb5b4 --- /dev/null +++ b/tests/expected/overrides-auto-module.md @@ -0,0 +1,54 @@ + + + + + + +# Auto Module + +Example module + +### *class* Point(x: [int](https://docs.python.org/3/library/functions.html#int), y: [str](https://docs.python.org/3/library/stdtypes.html#str)) + +A Point + + + +## Attributes + +x: int +: The x value + +y: str +: The y value + +#### x *: [int](https://docs.python.org/3/library/functions.html#int)* + +X value + +#### y *: [str](https://docs.python.org/3/library/stdtypes.html#str)* + +Y value + +### deprecated_function() + +Some old function. + +#### Deprecated +Deprecated since version 3.1: Use `other()` instead. + +### func1(param1: [int](https://docs.python.org/3/library/functions.html#int)) → [int](https://docs.python.org/3/library/functions.html#int) + +This is a function with a single parameter. +Thanks to github.com/remiconnesson. + +* **Parameters:** + **param1** – This is a single parameter. + +### func2(param1: [int](https://docs.python.org/3/library/functions.html#int), param2: [int](https://docs.python.org/3/library/functions.html#int)) → [str](https://docs.python.org/3/library/stdtypes.html#str) + +This is a function with two parameters. + +* **Parameters:** + * **param1** – This is the first parameter. + * **param2** – This is the second parameter.