{#- Template for Python functions. This template renders a Python function or method. Context: function (griffe.Function): The function to render. root (bool): Whether this is the root object, injected with `:::` in a Markdown page. heading_level (int): The HTML heading level to use. config (dict): The configuration options. -#} {% block logs scoped %} {#- Logging block. This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {{ log.debug("Rendering " + function.path) }} {% endblock logs %} {% import "language.html.jinja" as lang with context %} {#- Language module providing the `t` translation method. -#}
{% with obj = function, html_id = function.path %} {% if root %} {% set show_full_path = config.show_root_full_path %} {% set root_members = True %} {% elif root_members %} {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %} {% set root_members = False %} {% else %} {% set show_full_path = config.show_object_full_path %} {% endif %} {% set function_name = function.path if show_full_path else function.name %} {#- Brief or full function name depending on configuration. -#} {% set symbol_type = "method" if function.parent.is_class else "function" %} {#- Symbol type: method when parent is a class, function otherwise. -#} {% if not root or config.show_root_heading %} {% filter heading( heading_level, role="function", id=html_id, class="doc doc-heading", toc_label=((' ')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name), skip_inventory=config.skip_local_inventory, ) %} {% block heading scoped %} {#- Heading block. This block renders the heading for the function. -#} {% if config.show_symbol_type_heading %}{% endif %} {% if config.heading and root %} {{ config.heading }} {% elif config.separate_signature %} {{ function_name }} {% else %} {%+ filter highlight(language="python", inline=True) -%} {{ function_name }} {%- include "type_parameters.html.jinja" with context -%} {%- include "signature.html.jinja" with context -%} {%- endfilter %} {% endif %} {% endblock heading %} {% block labels scoped %} {#- Labels block. This block renders the labels for the function. -#} {% with labels = function.labels %} {% include "labels.html.jinja" with context %} {% endwith %} {% endblock labels %} {% endfilter %} {% block signature scoped %} {#- Signature block. This block renders the signature for the function, as well as its overloaded signatures if any. -#} {% if function.overloads and config.show_overloads %}
{% for overload in function.overloads %} {% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %} {{ overload.name }} {% endfilter %} {% endfor %}
{% endif %} {% if config.separate_signature and not (config.show_overloads and function.overloads and config.overloads_only) %} {% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %} {{ function.name }} {% endfilter %} {% endif %} {% endblock signature %} {% else %} {% if config.show_root_toc_entry %} {% filter heading( heading_level, role="function", id=html_id, toc_label=((' ')|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else function.name), hidden=True, skip_inventory=config.skip_local_inventory, ) %} {% endfilter %} {% endif %} {% set heading_level = heading_level - 1 %} {% endif %}
{% block contents scoped %} {#- Contents block. This block renders the contents of the function. It contains other blocks that users can override. Overriding the contents block allows to rearrange the order of the blocks. -#} {% block docstring scoped %} {#- Docstring block. This block renders the docstring for the function. -#} {% with docstring_sections = function.docstring.parsed %} {% include "docstring.html.jinja" with context %} {% endwith %} {% endblock docstring %} {% if config.backlinks %} {% endif %} {% block source scoped %} {#- Source block. This block renders the source code for the function. -#} {% if config.show_source and function.source %}
{{ lang.t("Source code in") }} {%- if function.relative_filepath.is_absolute() -%} {{ function.relative_package_filepath }} {%- else -%} {{ function.relative_filepath }} {%- endif -%} {{ function.source|highlight(language="python", linestart=function.lineno or 0, linenums=True) }}
{% endif %} {% endblock source %} {% endblock contents %}
{% endwith %}