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 request: include classname for class members #79

Open
couling opened this issue Jun 15, 2023 · 2 comments
Open

Feature request: include classname for class members #79

couling opened this issue Jun 15, 2023 · 2 comments
Labels
feature New feature or request

Comments

@couling
Copy link

couling commented Jun 15, 2023

Could there be an option (or options) to achieve a more python style headers for module members and class members.

In the python's own documentation, the full path of each class and object is not included. But for class members, the class name is included. Taking a random example, the module zipfile contains a class zipfile.ZipFile. All of the methods on that class are written as ZipFile.close(), ZipFile.getinfo(), ... See here: https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.close

The "include_full_path` options produce very verbose results.

@pawamoy
Copy link
Member

pawamoy commented Jun 15, 2023

Have you tried the following?

plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          show_root_full_path: false
          show_root_members_full_path: true

Docs: https://mkdocstrings.github.io/python/usage/configuration/headings/#show_root_members_full_path

EDIT: ah, I understand now. No, there's no such option. I'm open to adding one 🙂

@pawamoy
Copy link
Member

pawamoy commented Jul 21, 2023

Now that we have Jinja blocks in our templates, it's a bit easier to implement that with custom templates:

# mkdocs.yml
plugins:
- mkdocstrings:
    custom_templates: docs/templates
    ...

In docs/templates/python/material/function.html:

{% extends "_base/function.html" %}

{%- macro method_heading(function) -%}
  {%- if show_full_path -%}
    {{ function.path }}
  {%- elif function.parent.is_class -%}
    {{ function.parent.name }}.{{ function.name }}
  {%- else -%}
    {{ function.name }}
  {%- endif -%}
{%- endmacro -%}

{% block heading %}
  {% if config.separate_signature %}
    <span class="doc doc-object-name doc-function-name">{{ method_heading(function) }}</span>
  {% else %}
    {% filter highlight(language="python", inline=True) %}
      {{ method_heading(function) }}
      {% include "signature.html" with context %}
    {% endfilter %}
  {% endif %}
{% endblock heading %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants