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

feature: show_overloads #250

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading