From d57ad294d4c863a6477cf3c1bb2c22ca24ee8d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 29 Apr 2024 00:06:04 +0200 Subject: [PATCH] fixup! docs: Document Jinja templates --- .../templates/material/_base/signature.html.jinja | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html.jinja index 0835d987..2d87986c 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html.jinja @@ -10,13 +10,13 @@ Context: -#} {%- if config.show_signature -%} - {% block logs scoped %} + {%- block logs scoped -%} {#- Logging block. This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {{ log.debug("Rendering signature") }} - {% endblock logs %} + {%- endblock logs -%} {%- with -%} {%- set ns = namespace( @@ -31,6 +31,7 @@ Context: {%- for parameter in function.parameters -%} {%- if parameter.name not in ("self", "cls") or loop.index0 > 0 or not (function.parent and function.parent.is_class) -%} + {#- Handle parameter kind. -#} {%- if parameter.kind.value == "positional-only" -%} {%- set ns.has_pos_only = True -%} {%- else -%} @@ -42,6 +43,7 @@ Context: {%- endif -%} {%- endif -%} + {#- Prepare type annotation. -#} {%- if config.show_signature_annotations and parameter.annotation is not none -%} {%- set ns.equal = " = " -%} {%- if config.separate_signature and config.signature_crossrefs -%} @@ -56,14 +58,17 @@ Context: {%- set ns.annotation = "" -%} {%- endif -%} + {#- Prepare default value. -#} {%- if parameter.default is not none and parameter.kind.value != "variadic positional" and parameter.kind.value != "variadic keyword" -%} {%- set default = ns.equal + parameter.default|safe -%} {%- endif -%} + {#- TODO: Move inside kind handling above? -#} {%- if parameter.kind.value == "variadic positional" -%} {%- set ns.render_kw_only_separator = False -%} {%- endif -%} + {#- Render name, annotation and default. -#} {% if parameter.kind.value == "variadic positional" %}*{% elif parameter.kind.value == "variadic keyword" %}**{% endif -%} {{ parameter.name }}{{ ns.annotation }}{{ default }} {%- if not loop.last %}, {% endif -%} @@ -71,6 +76,8 @@ Context: {%- endif -%} {%- endfor -%} ) + + {#- Render return type. -#} {%- if config.show_signature_annotations and function.annotation and not (config.merge_init_into_class and function.name == "__init__" )