Skip to content

Commit 47868a1

Browse files
committed
fix: Fix templates for named docstring elements
1 parent 29b174c commit 47868a1

File tree

5 files changed

+102
-60
lines changed

5 files changed

+102
-60
lines changed

src/mkdocstrings/templates/python/material/_base/docstring/raises.html

+7-11
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@
4949
<tbody>
5050
{% for raises in section.value %}
5151
<tr>
52-
<td><code>{{ raises.name }}</code></td>
52+
<td>
53+
<span class="doc-raises-annotation">
54+
{% with expression = raises.annotation %}
55+
<code>{% include "expression.html" with context %}</code>
56+
{% endwith %}
57+
</span>
58+
</td>
5359
<td class="doc-raises-details">
5460
{{ raises.description|convert_markdown(heading_level, html_id) }}
55-
<p>
56-
{% if raises.annotation %}
57-
<span class="doc-raises-annotation">
58-
<b>TYPE:</b>
59-
{% with expression = raises.annotation %}
60-
<code>{% include "expression.html" with context %}</code>
61-
{% endwith %}
62-
</span>
63-
{% endif %}
64-
</p>
6561
</td>
6662
</tr>
6763
{% endfor %}

src/mkdocstrings/templates/python/material/_base/docstring/receives.html

+33-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{{ log.debug() }}
22
{% if config.docstring_section_style == "table" %}
3+
{% set name_column = section.value|selectattr("name")|any %}
34
<p><strong>{{ section.title or "Receives:" }}</strong></p>
45
<table>
56
<thead>
67
<tr>
8+
{% if name_column %}<th>Name</th>{% endif %}
79
<th>Type</th>
810
<th>Description</th>
911
</tr>
1012
</thead>
1113
<tbody>
12-
<tr>
13-
{% with receives = section.value %}
14+
{% for receives in section.value %}
15+
<tr>
16+
{% if name_column %}<td>{% if receives.name %}<code>{{ receives.name }}</code>{% endif %}</td>{% endif %}
1417
<td>
1518
{% if receives.annotation %}
1619
{% with expression = receives.annotation %}
@@ -19,24 +22,26 @@
1922
{% endif %}
2023
</td>
2124
<td>{{ receives.description|convert_markdown(heading_level, html_id) }}</td>
22-
{% endwith %}
23-
</tr>
25+
</tr>
26+
{% endfor %}
2427
</tbody>
2528
</table>
2629
{% elif config.docstring_section_style == "list" %}
2730
<p>{{ section.title or "Receives:" }}</p>
2831
<ul>
29-
{% with receives = section.value %}
32+
{% for receives in section.value %}
3033
<li class="field-body">
34+
{% if receives.name %}<b>{{ receives.name }}</b>{% endif %}
3135
{% if receives.annotation %}
3236
{% with expression = receives.annotation %}
37+
{% if receives.name %}({% endif %}
3338
<code>{% include "expression.html" with context %}</code>
39+
{% if receives.name %}){% endif %}
3440
{% endwith %}
35-
3641
{% endif %}
37-
{{ receives.description|convert_markdown(heading_level, html_id) }}
42+
{{ receives.description|convert_markdown(heading_level, html_id) }}
3843
</li>
39-
{% endwith %}
44+
{% endfor %}
4045
</ul>
4146
{% elif config.docstring_section_style == "spacy" %}
4247
<table>
@@ -47,21 +52,31 @@
4752
</tr>
4853
</thead>
4954
<tbody>
50-
{% for receive in section.value %}
55+
{% for receives in section.value %}
5156
<tr>
52-
<td><code>{{ receive.name }}</code></td>
53-
<td class="doc-receive-details">
54-
{{ receive.description|convert_markdown(heading_level, html_id) }}
55-
<p>
56-
{% if receive.annotation %}
57-
<span class="doc-receive-annotation">
57+
<td>
58+
{% if receives.name %}
59+
<code>{{ receives.name }}</code>
60+
{% elif receives.annotation %}
61+
<span class="doc-receives-annotation">
62+
{% with expression = receives.annotation %}
63+
<code>{% include "expression.html" with context %}</code>
64+
{% endwith %}
65+
</span>
66+
{% endif %}
67+
</td>
68+
<td class="doc-receives-details">
69+
{{ receives.description|convert_markdown(heading_level, html_id) }}
70+
{% if receives.name and receives.annotation %}
71+
<p>
72+
<span class="doc-receives-annotation">
5873
<b>TYPE:</b>
59-
{% with expression = receive.annotation %}
74+
{% with expression = receives.annotation %}
6075
<code>{% include "expression.html" with context %}</code>
6176
{% endwith %}
6277
</span>
63-
{% endif %}
64-
</p>
78+
</p>
79+
{% endif %}
6580
</td>
6681
</tr>
6782
{% endfor %}

src/mkdocstrings/templates/python/material/_base/docstring/returns.html

+27-7
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,38 @@
4545
</ul>
4646
{% elif config.docstring_section_style == "spacy" %}
4747
<table>
48+
<thead>
49+
<tr>
50+
<th><b>RETURNS</b></th>
51+
<th><b>DESCRIPTION</b></th>
52+
</tr>
53+
</thead>
4854
<tbody>
49-
<tr><td><b>RETURNS</b></td></tr>
5055
{% for returns in section.value %}
5156
<tr>
57+
<td>
58+
{% if returns.name %}
59+
<code>{{ returns.name }}</code>
60+
{% elif returns.annotation %}
61+
<span class="doc-returns-annotation">
62+
{% with expression = returns.annotation %}
63+
<code>{% include "expression.html" with context %}</code>
64+
{% endwith %}
65+
</span>
66+
{% endif %}
67+
</td>
5268
<td class="doc-returns-details">
5369
{{ returns.description|convert_markdown(heading_level, html_id) }}
54-
<p>
55-
<b>TYPE:</b>
56-
{% with expression = returns.annotation %}
57-
<code>{% include "expression.html" with context %}</code>
58-
{% endwith %}
59-
</p>
70+
{% if returns.name and returns.annotation %}
71+
<p>
72+
<span class="doc-returns-annotation">
73+
<b>TYPE:</b>
74+
{% with expression = returns.annotation %}
75+
<code>{% include "expression.html" with context %}</code>
76+
{% endwith %}
77+
</span>
78+
</p>
79+
{% endif %}
6080
</td>
6181
</tr>
6282
{% endfor %}

src/mkdocstrings/templates/python/material/_base/docstring/warns.html

+7-11
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,15 @@
4949
<tbody>
5050
{% for warns in section.value %}
5151
<tr>
52-
<td><code>{{ warns.name }}</code></td>
52+
<td>
53+
<span class="doc-warns-annotation">
54+
{% with expression = warns.annotation %}
55+
<code>{% include "expression.html" with context %}</code>
56+
{% endwith %}
57+
</span>
58+
</td>
5359
<td class="doc-warns-details">
5460
{{ warns.description|convert_markdown(heading_level, html_id) }}
55-
<p>
56-
{% if warns.annotation %}
57-
<span class="doc-warns-annotation">
58-
<b>TYPE:</b>
59-
{% with expression = warns.annotation %}
60-
<code>{% include "expression.html" with context %}</code>
61-
{% endwith %}
62-
</span>
63-
{% endif %}
64-
</p>
6561
</td>
6662
</tr>
6763
{% endfor %}

src/mkdocstrings/templates/python/material/_base/docstring/yields.html

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{{ log.debug() }}
22
{% if config.docstring_section_style == "table" %}
3+
{% set name_column = section.value|selectattr("name")|any %}
34
<p><strong>{{ section.title or "Yields:" }}</strong></p>
45
<table>
56
<thead>
67
<tr>
8+
{% if name_column %}<th>Name</th>{% endif %}
79
<th>Type</th>
810
<th>Description</th>
911
</tr>
1012
</thead>
1113
<tbody>
12-
<tr>
13-
{% with yields = section.value %}
14+
{% for yields in section.value %}
15+
<tr>
16+
{% if name_column %}<td>{% if yields.name %}<code>{{ yields.name }}</code>{% endif %}</td>{% endif %}
1417
<td>
1518
{% if yields.annotation %}
1619
{% with expression = yields.annotation %}
@@ -19,24 +22,26 @@
1922
{% endif %}
2023
</td>
2124
<td>{{ yields.description|convert_markdown(heading_level, html_id) }}</td>
22-
{% endwith %}
23-
</tr>
25+
</tr>
26+
{% endfor %}
2427
</tbody>
2528
</table>
2629
{% elif config.docstring_section_style == "list" %}
2730
<p>{{ section.title or "Yields:" }}</p>
2831
<ul>
29-
{% with yields = section.value %}
32+
{% for yields in section.value %}
3033
<li class="field-body">
34+
{% if yields.name %}<b>{{ yields.name }}</b>{% endif %}
3135
{% if yields.annotation %}
3236
{% with expression = yields.annotation %}
37+
{% if yields.name %}({% endif %}
3338
<code>{% include "expression.html" with context %}</code>
39+
{% if yields.name %}){% endif %}
3440
{% endwith %}
35-
3641
{% endif %}
37-
{{ yields.description|convert_markdown(heading_level, html_id) }}
42+
{{ yields.description|convert_markdown(heading_level, html_id) }}
3843
</li>
39-
{% endwith %}
44+
{% endfor %}
4045
</ul>
4146
{% elif config.docstring_section_style == "spacy" %}
4247
<table>
@@ -49,19 +54,29 @@
4954
<tbody>
5055
{% for yields in section.value %}
5156
<tr>
52-
<td><code>{{ yields.name }}</code></td>
57+
<td>
58+
{% if yields.name %}
59+
<code>{{ yields.name }}</code>
60+
{% elif yields.annotation %}
61+
<span class="doc-yields-annotation">
62+
{% with expression = yields.annotation %}
63+
<code>{% include "expression.html" with context %}</code>
64+
{% endwith %}
65+
</span>
66+
{% endif %}
67+
</td>
5368
<td class="doc-yields-details">
5469
{{ yields.description|convert_markdown(heading_level, html_id) }}
55-
<p>
56-
{% if yields.annotation %}
70+
{% if yields.name and yields.annotation %}
71+
<p>
5772
<span class="doc-yields-annotation">
5873
<b>TYPE:</b>
5974
{% with expression = yields.annotation %}
6075
<code>{% include "expression.html" with context %}</code>
6176
{% endwith %}
6277
</span>
63-
{% endif %}
64-
</p>
78+
</p>
79+
{% endif %}
6580
</td>
6681
</tr>
6782
{% endfor %}

0 commit comments

Comments
 (0)