mkdocstrings/python

bug: merge_init_into_class not working

Closed this issue · 7 comments

Description of the bug

I am trying to show use merge_init_into_class.
I have set show_if_no_docstring to true,
filters to ["!^_", "^__init__$"],
show_signature to true.

Methods are shown with their signatures and docstrings.
However classes are shown without signature and only with their docstring.
Class inits are shown with signature and without docstring (they don't have one).
Classes are shown with their docstring but without signature.

To Reproduce

python/amodule.py

class A:
    """
    This is class A
    """

    def __init__(self, a: str):
        self.a = a

reference.md

::: amodule

mkdocs.yml

site_name: MySite
theme: readthedocs

nav:
  - "reference.md"

plugins:
  - mkdocstrings:
      handlers:
        python:
          paths: [python]
          options:
            heading_level: 3
            merge_init_into_class: true
            show_bases: false
            show_root_toc_entry: false
            show_source: false
            show_object_full_path: false
            members_order: source
            show_signature: true
            show_if_no_docstring: true
            filters: ["!^_", "^__init__$"]

serve with

mkdocs serve

Expected behavior

I would like to see the class name with the init signature and the class docstring.
So from the example above, I would like to see something like:

<h3>A(a)</h3>
This is class A

But currently it shows something like this:

<h3>A</h3>
This is class A

<h3>__init__(a)</h3>

Environment information

python -m mkdocstrings_handlers.python.debug
fails with No module named mkdocstrings_handlers.python.debug.

I have installed:

mkdocs==1.5.3
mkdocstrings[python]==0.24.0

Hello, thanks for the report.

Unfortunately I cannot reproduce the issue you describe. I copy pasted your snippets into a local project, served the docs, and this is what I get:

merge_init

HTML:

<div class="doc doc-object doc-class">
    <h3 id="proj.mod.A" class="doc doc-heading">
        <code class="highlight language-python">A(a)</code>
    </h3>
    <div class="doc doc-contents ">
        <p>This is class A</p>
        <div class="doc doc-children">
            <div class="doc doc-object doc-attribute">
                <h4 id="proj.mod.A.a" class="doc doc-heading">
                    <code class="highlight language-python">a = a</code>

                    <span class="doc doc-labels">
      <small class="doc doc-label doc-label-instance-attribute"><code>instance-attribute</code></small>
  </span>
                </h4>
                <div class="doc doc-contents ">
                </div>
            </div>
        </div>
    </div>
</div>

The rendering looks correct given the configured options.

Even with the same version?

I have a deployed example (of the missing init args) here: https://magic-soup.readthedocs.io/en/latest/reference/#magicsoup.world.World

I tried with latest versions, which you should get too given the requirements you specified:

  • mkdocs 1.5.3
  • mkdocstrings[python] 0.24.0

What version of mkdocstrings-python do you have installed?

The error you mention suggests you're not using the latest version:

python -m mkdocstrings_handlers.python.debug
fails with No module named mkdocstrings_handlers.python.debug

Let me try with your own magicsoup project to make sure, thanks for sharing that link 🙂

Seems to be working there too!

magicsoup

Yes, updating mkdocstrings-python fixed it. And I noticed, I can have show_if_no_docstring: false.
Thanks for the help!

You're welcome, thank you for reporting back!