Skip to content

Commit

Permalink
Add support for autodoc_typehints=signature
Browse files Browse the repository at this point in the history
Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
  • Loading branch information
liran-funaro committed Aug 27, 2024
1 parent a557584 commit f9ecbbc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions sphinx_markdown_builder/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ def visit_bullet_list(self, node):
# desc_parameterlist
# desc_annotation
# desc_parameter
# desc_returns
# desc_content
# field_list
# field
Expand Down Expand Up @@ -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)))
Expand Down
54 changes: 54 additions & 0 deletions tests/expected/overrides-auto-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<meta name="author" content="Liran Funaro"/>
<meta name="copyright" content="Copyright (c) 2023-2024, Liran Funaro."/>
<meta name="version" content="0.6.6"/>

<a id="auto-module"></a>

# 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

<a id="attributes"></a>

## 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.

0 comments on commit f9ecbbc

Please sign in to comment.