Skip to content

Commit 0f07c2e

Browse files
pawamoyWillDaSilva
andcommitted
feat: Add show_signature rendering option
Co-authored-by: Will Da Silva <[email protected]>
1 parent 8f0aa42 commit 0f07c2e

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/mkdocstrings/handlers/python/renderer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class PythonRenderer(BaseRenderer):
7070
"show_object_full_path": False,
7171
"show_category_heading": False,
7272
"show_if_no_docstring": False,
73+
"show_signature": True,
7374
"show_signature_annotations": False,
7475
"separate_signature": False,
7576
"line_length": 60,
@@ -91,7 +92,8 @@ class PythonRenderer(BaseRenderer):
9192
**`show_root_members_full_path`** | `bool` | Show the full Python path of objects that are children of the root object (for example, classes in a module). When False, `show_object_full_path` overrides. | `False`
9293
**`show_category_heading`** | `bool` | When grouped by categories, show a heading for each category. | `False`
9394
**`show_if_no_docstring`** | `bool` | Show the object heading even if it has no docstring or children with docstrings. | `False`
94-
**`show_signature_annotations`** | `bool` | Show the type annotations in methods and functions signatures. | `False`
95+
**`show_signature`** | `bool` | Show method and function signatures. | `True`
96+
**`show_signature_annotations`** | `bool` | Show the type annotations in method and function signatures. | `False`
9597
**`separate_signature`** | `bool` | Whether to put the whole signature in a foldable code block below the heading. | `False`
9698
**`line_length`** | `int` | Maximum line length when formatting code. | `60`
9799
**`show_source`** | `bool` | Show the source code of this object. | `True`
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
{{ log.debug() }}
2-
{%- with -%}
3-
{%- set ns = namespace(render_pos_only_separator=True, render_kw_only_separator=True, equal="=") -%}
2+
{%- if config.show_signature -%}
3+
{%- with -%}
44

5-
{%- if config.show_signature_annotations -%}
6-
{%- set ns.equal = " = " -%}
7-
{%- endif -%}
5+
{%- set ns = namespace(render_pos_only_separator=True, render_kw_only_separator=True, equal="=") -%}
86

9-
(
10-
{%- for parameter in function.parameters -%}
7+
{%- if config.show_signature_annotations -%}
8+
{%- set ns.equal = " = " -%}
9+
{%- endif -%}
1110

12-
{%- if parameter.kind.value == "positional-only" -%}
13-
{%- if ns.render_pos_only_separator -%}
14-
{%- set ns.render_pos_only_separator = False %}/, {% endif -%}
15-
{%- elif parameter.kind.value == "keyword-only" -%}
16-
{%- if ns.render_kw_only_separator -%}
17-
{%- set ns.render_kw_only_separator = False %}*, {% endif -%}
18-
{%- endif -%}
11+
(
12+
{%- for parameter in function.parameters -%}
1913

20-
{%- if config.show_signature_annotations and parameter.annotation is not none -%}
21-
{%- set annotation = ": " + parameter.annotation|safe -%}
22-
{%- endif -%}
14+
{%- if parameter.kind.value == "positional-only" -%}
15+
{%- if ns.render_pos_only_separator -%}
16+
{%- set ns.render_pos_only_separator = False %}/, {% endif -%}
17+
{%- elif parameter.kind.value == "keyword-only" -%}
18+
{%- if ns.render_kw_only_separator -%}
19+
{%- set ns.render_kw_only_separator = False %}*, {% endif -%}
20+
{%- endif -%}
2321

24-
{%- if parameter.default is not none and parameter.kind.value != "variadic positional" and parameter.kind.value != "variadic keyword" -%}
25-
{%- set default = ns.equal + parameter.default|safe -%}
26-
{%- endif -%}
22+
{%- if config.show_signature_annotations and parameter.annotation is not none -%}
23+
{%- set annotation = ": " + parameter.annotation|safe -%}
24+
{%- endif -%}
2725

28-
{%- if parameter.kind.value == "variadic positional" -%}
29-
{%- set ns.render_kw_only_separator = False -%}
30-
{%- endif -%}
26+
{%- if parameter.default is not none and parameter.kind.value != "variadic positional" and parameter.kind.value != "variadic keyword" -%}
27+
{%- set default = ns.equal + parameter.default|safe -%}
28+
{%- endif -%}
3129

32-
{{ parameter.name }}{{ annotation }}{{ default }}
33-
{%- if not loop.last %}, {% endif -%}
30+
{%- if parameter.kind.value == "variadic positional" -%}
31+
{%- set ns.render_kw_only_separator = False -%}
32+
{%- endif -%}
3433

35-
{%- endfor -%}
36-
)
37-
{%- if config.show_signature_annotations and "return_annotation" in signature %} -> {{ signature.return_annotation }}{%- endif -%}
34+
{{ parameter.name }}{{ annotation }}{{ default }}
35+
{%- if not loop.last %}, {% endif -%}
3836

39-
{%- endwith -%}
37+
{%- endfor -%}
38+
)
39+
{%- if config.show_signature_annotations and "return_annotation" in signature %} -> {{ signature.return_annotation }}{%- endif -%}
40+
41+
{%- endwith -%}
42+
{%- endif -%}

0 commit comments

Comments
 (0)