From 6c5b5c341940af9425b3de0672ac400794b3f6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 26 Nov 2024 15:01:26 +0100 Subject: [PATCH] fix: Don't merge parent `__init__` docstring into class docstring if such inherited method wasn't selected through the `inherited_members` configuration option Issue-189: https://github.com/mkdocstrings/python/issues/189 --- .../templates/material/_base/class.html.jinja | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja index da48545..eac70be 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja @@ -132,13 +132,17 @@ Context: {% include "docstring"|get_template with context %} {% endwith %} {% if config.merge_init_into_class %} - {% if "__init__" in all_members and all_members["__init__"].has_docstring %} - {% with function = all_members["__init__"] %} - {% with obj = function, docstring_sections = function.docstring.parsed %} - {% include "docstring"|get_template with context %} + {# We don't want to merge the inherited `__init__` method docstring into the class docstring #} + {# if such inherited method was not selected through `inherited_members`. #} + {% with check_members = all_members if (config.inherited_members is true or (config.inherited_members is iterable and "__init__" in config.inherited_members)) else class.members %} + {% if "__init__" in check_members and check_members["__init__"].has_docstring %} + {% with function = check_members["__init__"] %} + {% with obj = function, docstring_sections = function.docstring.parsed %} + {% include "docstring"|get_template with context %} + {% endwith %} {% endwith %} - {% endwith %} - {% endif %} + {% endif %} + {% endwith %} {% endif %} {% endblock docstring %}