Skip to content

Commit 6c5b5c3

Browse files
committed
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: #189
1 parent c6dab06 commit 6c5b5c3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja

+10-6
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ Context:
132132
{% include "docstring"|get_template with context %}
133133
{% endwith %}
134134
{% if config.merge_init_into_class %}
135-
{% if "__init__" in all_members and all_members["__init__"].has_docstring %}
136-
{% with function = all_members["__init__"] %}
137-
{% with obj = function, docstring_sections = function.docstring.parsed %}
138-
{% include "docstring"|get_template with context %}
135+
{# We don't want to merge the inherited `__init__` method docstring into the class docstring #}
136+
{# if such inherited method was not selected through `inherited_members`. #}
137+
{% 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 %}
138+
{% if "__init__" in check_members and check_members["__init__"].has_docstring %}
139+
{% with function = check_members["__init__"] %}
140+
{% with obj = function, docstring_sections = function.docstring.parsed %}
141+
{% include "docstring"|get_template with context %}
142+
{% endwith %}
139143
{% endwith %}
140-
{% endwith %}
141-
{% endif %}
144+
{% endif %}
145+
{% endwith %}
142146
{% endif %}
143147
{% endblock docstring %}
144148

0 commit comments

Comments
 (0)