Skip to content

Class docstrings are never displayed #19

Closed
@francois-rozet

Description

@francois-rozet

Describe the bug

The class docstrings are never displayed.

Screenshots

With the following class

class SSIM(nn.Module):
    r"""Creates a criterion that measures the SSIM
    between an input and a target.

    Args:
        window_size: The size of the window.
        sigma: The standard deviation of the window.
        n_channels: The number of channels $C$.
        reduction: Specifies the reduction to apply to the output:
            `'none'` | `'mean'` | `'sum'`.
    """

    def __init__(
        self,
        window_size: int = 11,
        sigma: float = 1.5,
        n_channels: int = 3,
        reduction: str = 'mean',
        **kwargs,
    ):
        pass

I get

image

when merge_init_into_class is false and

image

when it is true.

System (please complete the following information):

  • mkdocstrings-python version: 0.6.6
  • Python version: 3.8.10
  • OS: Ubuntu 20.04
plugins:
  - mkdocstrings:
      default_handler: python
      handlers:
        python:
          selection:
            docstring_style: google
          rendering:
            docstring_section_style: list
            heading_level: 3
            members_order: source
            merge_init_into_class: true
            show_bases: false
            show_if_no_docstring: false
            show_root_full_path: true
            show_root_heading: true
            show_source: false
            show_submodules: false
      watch:
        - piqa

Additional context

If I understand correctly the following logic, a docstring is displayed only if merge_init_into_class=true and the __init__ function has a docstring, but it is never the one from the class itself.

{% if config.merge_init_into_class %}
{% if "__init__" in class.members and class.members["__init__"].has_docstring %}
{% with docstring_sections = class.members["__init__"].docstring.parsed %}
{% include "docstring.html" with context %}
{% endwith %}
{% endif %}
{% endif %}

I think that if merge_init_into_class=false or __init__ does not have a docstring, the docstring of the class should be displayed, if any. If merge_init_into_class=true and both __init__ and the class have a docstring, it is more complicated but IMO, the class docstring should have precedence.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions