Skip to content

Commit 4a5ee10

Browse files
authored
feat: Add option to show/hide overloads
PR-250: #250
1 parent 20cae2c commit 4a5ee10

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

docs/usage/configuration/signatures.md

+49
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,55 @@ function(param1, param2=None)
433433
////
434434
///
435435

436+
[](){#option-show_overloads}
437+
## `show_overloads`
438+
439+
Whether to render function / method overloads.
440+
441+
```yaml title="in mkdocs.yml (global configuration)"
442+
plugins:
443+
- mkdocstrings:
444+
handlers:
445+
python:
446+
options:
447+
show_overloads: true
448+
```
449+
450+
```md title="or in docs/some_page.md (local configuration)"
451+
::: path.to.module
452+
options:
453+
show_overloads: false
454+
```
455+
456+
/// admonition | Preview
457+
type: preview
458+
//// tab | With overloads
459+
<h2>function</h2>
460+
461+
462+
```python
463+
@overload
464+
function(param1: int): ...
465+
466+
@overload
467+
function(param1: str): ...
468+
469+
function(param1: str | int)
470+
```
471+
Function docstring.
472+
473+
////
474+
//// tab | Without overloads
475+
<h2>function</h2>
476+
477+
```python
478+
function(param1: str | int)
479+
```
480+
Function docstring.
481+
482+
////
483+
///
484+
436485
[](){#option-signature_crossrefs}
437486
## `signature_crossrefs`
438487

src/mkdocstrings_handlers/python/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ class PythonInputOptions:
568568
),
569569
] = False
570570

571+
show_overloads: Annotated[
572+
bool,
573+
Field(
574+
group="signatures",
575+
description="Show the overloads of a function or method.",
576+
),
577+
] = True
578+
571579
separate_signature: Annotated[
572580
bool,
573581
Field(

src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Context:
8282
{% if config.merge_init_into_class %}
8383
{% if "__init__" in all_members %}
8484
{% with function = all_members["__init__"] %}
85-
{% if function.overloads %}
85+
{% if function.overloads and config.show_overloads %}
8686
<div class="doc-overloads">
8787
{% for overload in function.overloads %}
8888
{% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}

src/mkdocstrings_handlers/python/templates/material/_base/function.html.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Context:
8080
This block renders the signature for the function,
8181
as well as its overloaded signatures if any.
8282
-#}
83-
{% if function.overloads %}
83+
{% if function.overloads and config.show_overloads %}
8484
<div class="doc-overloads">
8585
{% for overload in function.overloads %}
8686
{% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}

0 commit comments

Comments
 (0)