Skip to content

Commit

Permalink
feat: Add option to show/hide overloads
Browse files Browse the repository at this point in the history
PR-250: #250
  • Loading branch information
reteps authored Feb 17, 2025
1 parent 20cae2c commit 4a5ee10
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
49 changes: 49 additions & 0 deletions docs/usage/configuration/signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,55 @@ function(param1, param2=None)
////
///

[](){#option-show_overloads}
## `show_overloads`

Whether to render function / method overloads.

```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_overloads: true
```

```md title="or in docs/some_page.md (local configuration)"
::: path.to.module
options:
show_overloads: false
```

/// admonition | Preview
type: preview
//// tab | With overloads
<h2>function</h2>


```python
@overload
function(param1: int): ...
@overload
function(param1: str): ...
function(param1: str | int)
```
Function docstring.

////
//// tab | Without overloads
<h2>function</h2>

```python
function(param1: str | int)
```
Function docstring.

////
///

[](){#option-signature_crossrefs}
## `signature_crossrefs`

Expand Down
8 changes: 8 additions & 0 deletions src/mkdocstrings_handlers/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ class PythonInputOptions:
),
] = False

show_overloads: Annotated[
bool,
Field(
group="signatures",
description="Show the overloads of a function or method.",
),
] = True

separate_signature: Annotated[
bool,
Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Context:
{% if config.merge_init_into_class %}
{% if "__init__" in all_members %}
{% with function = all_members["__init__"] %}
{% if function.overloads %}
{% if function.overloads and config.show_overloads %}
<div class="doc-overloads">
{% for overload in function.overloads %}
{% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Context:
This block renders the signature for the function,
as well as its overloaded signatures if any.
-#}
{% if function.overloads %}
{% if function.overloads and config.show_overloads %}
<div class="doc-overloads">
{% for overload in function.overloads %}
{% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}
Expand Down

0 comments on commit 4a5ee10

Please sign in to comment.