Skip to content

Commit 952472e

Browse files
committed
merge class/init parameters
1 parent 7e12644 commit 952472e

File tree

7 files changed

+351
-449
lines changed

7 files changed

+351
-449
lines changed

docs/snippets/package/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from importlib import metadata
2+
from typing import Iterator, TypeVar
23

34
def get_version(dist: str = "mkdocstrings-python") -> str:
45
"""Get version of the given distribution.
@@ -17,3 +18,40 @@ def get_version(dist: str = "mkdocstrings-python") -> str:
1718

1819
current_version: str = get_version(dist="mkdocstrings-python")
1920
"""Current package version."""
21+
22+
23+
class MagicBag[T: (str, bytes) = str](list[T]):
24+
"""A magic bag of items.
25+
26+
Type parameters:
27+
T: Some type.
28+
"""
29+
30+
def __init__[U: (int, bool)](self, *args: T, flag1: U | None = None, flag2: U | None = None) -> None:
31+
"""Initialize bag.
32+
33+
Type parameters:
34+
U: Some flag type.
35+
36+
Parameters:
37+
flag1: Some flag.
38+
flag2: Some flag.
39+
"""
40+
super().__init__(args)
41+
self.flag1 = flag1
42+
self.flag2 = flag2
43+
44+
def mutate[K](self, item: T, into: K) -> K:
45+
"""Shake the bag to mutate an item into something else (and eject it).
46+
47+
Type parameters:
48+
K: Some other type.
49+
50+
Parameters:
51+
item: The item to mutate.
52+
into: Mutate the item into something like this.
53+
54+
Returns:
55+
The mutated item.
56+
"""
57+
...

docs/usage/configuration/headings.md

Lines changed: 52 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -246,232 +246,76 @@ plugins:
246246
/// admonition | Preview: Cross-references
247247
type: preview
248248

249-
<div class="doc doc-object doc-function">
250-
<h3 id="package.set_element" class="doc doc-heading">
251-
<code class="doc-symbol doc-symbol-heading doc-symbol-function"></code> <span
252-
class="doc doc-object-name doc-function-name"><mark data-md-highlight="">set_e</mark>lement</span>
253-
<a href="#package.set_element" class="headerlink" title="Permanent link">¤</a>
254-
</h3>
255-
<div class="language-python doc-signature highlight">
256-
<pre id="__code_10"><span></span><button class="md-clipboard md-icon" title="Copy to clipboard" data-clipboard-target="#__code_10 > code"></button><code><span class="nf"><mark data-md-highlight="">set_e</mark>lement</span><span class="p">[</span><span class="n"><a class="autorefs autorefs-internal" href="#package.set_element:T">T</a></span><span class="p">](</span><span class="n"><a class="autorefs autorefs-internal" href="#package.set_element(element)">element</a></span><span class="p">:</span> <span class="n"><a class="autorefs autorefs-internal" title="package.set_element:T" href="#package.set_element:T">T</a></span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span>
257-
</code></pre>
258-
</div>
259-
<div class="doc doc-contents first">
260-
<p>Set element.</p>
261-
<p><span class="doc-section-title">Parameters:</span></p>
262-
<ul>
263-
<li class="doc-section-item field-body">
264-
<h4 id="package.set_element(element)" class="doc doc-heading doc-heading-parameter"> <b><code>element</code></b>
265-
<a href="#package.set_element(element)" class="headerlink" title="Permanent link">¤</a>
266-
</h4>
267-
(<code><a class="autorefs autorefs-internal" title="package.set_element:T" href="#package.set_element:T">T</a></code>)
268-
269-
<div class="doc-md-description">
270-
<p>The element to set.</p>
271-
</div>
272-
</li>
273-
</ul>
274-
<p><span class="doc-section-title">Type Parameters:</span></p>
275-
<ul>
276-
<li class="doc-section-item field-body">
277-
<h4 id="package.set_element:T" class="doc doc-heading doc-heading-type_parameter"> <b><code>T</code></b>
278-
<a href="#package.set_element:T" class="headerlink" title="Permanent link">¤</a>
279-
</h4> –
280-
<div class="doc-md-description">
281-
<p>The type of the element.</p>
282-
</div>
283-
</li>
284-
</ul>
285-
</div>
286-
</div>
249+
```md exec="on"
250+
::: package.MagicBag
251+
options:
252+
heading_level: 3
253+
docstring_section_style: list
254+
show_bases: true
255+
summary: false
256+
separate_signature: true
257+
type_parameter_headings: true
258+
```
287259

288260
///
289261

290-
/// admonition | Preview: Type parameters sections
262+
/// admonition | Preview: Type parameter sections
291263
type: preview
292264

293265
//// tab | Table style
294-
<div class="doc doc-object doc-function">
295-
<div class="doc doc-contents first">
296-
<p><span class="doc-section-title">Parameters:</span></p>
297-
<div class="md-typeset__scrollwrap">
298-
<div class="md-typeset__table">
299-
<table>
300-
<thead>
301-
<tr>
302-
<th>Name</th>
303-
<th>Type</th>
304-
<th>Description</th>
305-
<th>Default</th>
306-
</tr>
307-
</thead>
308-
<tbody>
309-
<tr class="doc-section-item">
310-
<td>
311-
<h3 id="package.set_element(element)" class="doc doc-heading doc-heading-parameter">
312-
<code>element</code>
313-
<a href="#package.set_element(element)" class="headerlink" title="Permanent link">¤</a>
314-
</h3>
315-
</td>
316-
<td>
317-
<code><a class="autorefs autorefs-internal" title="package.set_element:T" href="#package.set_element:T">T</a></code>
318-
</td>
319-
<td>
320-
<div class="doc-md-description">
321-
<p>The element to set.</p>
322-
</div>
323-
</td>
324-
<td>
325-
<em>required</em>
326-
</td>
327-
</tr>
328-
</tbody>
329-
</table>
330-
</div>
331-
</div>
332-
<p><span class="doc-section-title">Type Parameters:</span></p>
333-
<div class="md-typeset__scrollwrap">
334-
<div class="md-typeset__table">
335-
<table>
336-
<thead>
337-
<tr>
338-
<th>Name</th>
339-
<th>Bound or Constraints</th>
340-
<th>Description</th>
341-
<th>Default</th>
342-
</tr>
343-
</thead>
344-
<tbody>
345-
<tr class="doc-section-item">
346-
<td>
347-
<h3 id="package.set_element:T" class="doc doc-heading doc-heading-type_parameter"> <code>T</code>
348-
<a href="#package.set_element:T" class="headerlink" title="Permanent link">¤</a>
349-
</h3>
350-
</td>
351-
<td>
352-
</td>
353-
<td>
354-
<div class="doc-md-description">
355-
<p>The type of the element.</p>
356-
</div>
357-
</td>
358-
<td>
359-
<em>required</em>
360-
</td>
361-
</tr>
362-
</tbody>
363-
</table>
364-
</div>
365-
</div>
366-
</div>
367-
</div>
266+
```md exec="on"
267+
::: package.MagicBag
268+
options:
269+
members: false
270+
heading_level: 3
271+
show_root_heading: false
272+
show_root_toc_entry: false
273+
parameter_headings: true
274+
docstring_section_style: table
275+
show_docstring_description: false
276+
show_docstring_parameters: false
277+
show_docstring_returns: false
278+
```
368279
////
369280

370281
//// tab | List style
371-
<div class="doc doc-object doc-function">
372-
<div class="doc doc-contents first">
373-
<p><span class="doc-section-title">Parameters:</span></p>
374-
<ul>
375-
<li class="doc-section-item field-body">
376-
<h3 id="package.set_element(element)" class="doc doc-heading doc-heading-parameter"> <b><code>element</code></b>
377-
<a href="#package.set_element(element)" class="headerlink" title="Permanent link">¤</a>
378-
</h3>
379-
(<code><a class="autorefs autorefs-internal" title="package.set_element:T" href="#package.set_element:T">T</a></code>)
380-
381-
<div class="doc-md-description">
382-
<p>The element to set.</p>
383-
</div>
384-
</li>
385-
</ul>
386-
<p><span class="doc-section-title">Type Parameters:</span></p>
387-
<ul>
388-
<li class="doc-section-item field-body">
389-
<h3 id="package.set_element:T" class="doc doc-heading doc-heading-type_parameter"> <b><code>T</code></b>
390-
<a href="#package.set_element:T" class="headerlink" title="Permanent link">¤</a>
391-
</h3> –
392-
<div class="doc-md-description">
393-
<p>The type of the element.</p>
394-
</div>
395-
</li>
396-
</ul>
397-
</div>
398-
</div>
282+
```md exec="on"
283+
::: package.MagicBag
284+
options:
285+
members: false
286+
heading_level: 3
287+
show_root_heading: false
288+
show_root_toc_entry: false
289+
parameter_headings: true
290+
docstring_section_style: list
291+
show_docstring_description: false
292+
show_docstring_parameters: false
293+
show_docstring_returns: false
294+
```
399295
////
400296

401297
//// tab | Spacy style
402-
<div class="doc doc-object doc-function">
403-
<div class="doc doc-contents first">
404-
<div class="md-typeset__scrollwrap">
405-
<div class="md-typeset__table">
406-
<table>
407-
<thead>
408-
<tr>
409-
<th><span class="doc-section-title">PARAMETER</span></th>
410-
<th><span>DESCRIPTION</span></th>
411-
</tr>
412-
</thead>
413-
<tbody>
414-
<tr class="doc-section-item">
415-
<td>
416-
<h3 id="package.set_element(element)" class="doc doc-heading doc-heading-parameter">
417-
<code>element</code>
418-
<a href="#package.set_element(element)" class="headerlink" title="Permanent link">¤</a>
419-
</h3>
420-
</td>
421-
<td class="doc-param-details">
422-
<div class="doc-md-description">
423-
<p>The element to set.</p>
424-
</div>
425-
<p>
426-
<span class="doc-param-annotation">
427-
<b>TYPE:</b>
428-
<code><a class="autorefs autorefs-internal" title="package.set_element:T" href="#package.set_element:T">T</a></code>
429-
</span>
430-
</p>
431-
</td>
432-
</tr>
433-
</tbody>
434-
</table>
435-
</div>
436-
</div>
437-
<div class="md-typeset__scrollwrap">
438-
<div class="md-typeset__table">
439-
<table>
440-
<thead>
441-
<tr>
442-
<th><span class="doc-section-title">TYPE PARAMETER</span></th>
443-
<th><span>DESCRIPTION</span></th>
444-
</tr>
445-
</thead>
446-
<tbody>
447-
<tr class="doc-section-item">
448-
<td>
449-
<h3 id="package.set_element:T" class="doc doc-heading doc-heading-type_parameter"> <code>T</code>
450-
<a href="#package.set_element:T" class="headerlink" title="Permanent link">¤</a>
451-
</h3>
452-
</td>
453-
<td class="doc-type_param-details">
454-
<div class="doc-md-description">
455-
<p>The type of the element.</p>
456-
</div>
457-
<p>
458-
</p>
459-
</td>
460-
</tr>
461-
</tbody>
462-
</table>
463-
</div>
464-
</div>
465-
</div>
466-
</div>
298+
```md exec="on"
299+
::: package.MagicBag
300+
options:
301+
members: false
302+
heading_level: 3
303+
show_root_heading: false
304+
show_root_toc_entry: false
305+
parameter_headings: true
306+
docstring_section_style: spacy
307+
show_docstring_description: false
308+
show_docstring_parameters: false
309+
show_docstring_returns: false
310+
```
467311
////
468312
///
469313

470314
/// admonition | Preview: Table of contents (with symbol types)
471315
type: preview
472316

473-
<code class="doc-symbol doc-symbol-toc doc-symbol-function"></code> set_element<br>
474-
<code class="doc-symbol doc-symbol-toc doc-symbol-type_parameter" style="margin-left: 16px;"></code> T
317+
<code class="doc-symbol doc-symbol-toc doc-symbol-function"></code> mutate<br>
318+
<code class="doc-symbol doc-symbol-toc doc-symbol-type_parameter" style="margin-left: 16px;"></code> U
475319

476320
To customize symbols, see [Customizing symbol types](../customization.md/#symbol-types).
477321

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,9 @@ Context:
5656
{% with function = all_members["__init__"] %}
5757
{%+ filter highlight(language="python", inline=True) %}
5858
{{ class_name -}}
59-
{%- if config.show_signature_annotations and config.show_signature_type_parameters -%}
60-
{# TODO: Merge type parameters instead of concatenating them. #}
59+
{%- with obj = function -%}
6160
{%- include "type_parameters"|get_template with context -%}
62-
{% if function.is_generic %}
63-
{%- with obj = function -%}
64-
{%- include "type_parameters"|get_template with context -%}
65-
{%- endwith -%}
66-
{%- endif -%}
67-
{%- endif -%}
61+
{%- endwith -%}
6862
{%- include "signature"|get_template with context -%}
6963
{% endfilter %}
7064
{% endwith %}
@@ -101,7 +95,6 @@ Context:
10195
If the `__init__` method or any overloads are generic, they are rendered as methods if
10296
`merge_init_into_class`, `separate_signature` and `show_signature_type_parameters` are enabled.
10397
-#}
104-
{# TODO: Merge type parameters of class and its `__init__` method. #}
10598
{% if config.merge_init_into_class and "__init__" in all_members %}
10699
{% with function = all_members["__init__"] %}
107100
{% if function.overloads and config.show_overloads %}

0 commit comments

Comments
 (0)