Skip to content

Commit 68fe870

Browse files
committed
Add support for PEP 695 type parameters and type aliases
1 parent a373895 commit 68fe870

37 files changed

+1546
-69
lines changed

docs/schema.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
"type": "boolean",
145145
"default": false
146146
},
147+
"show_signature_type_parameters": {
148+
"title": "Show the type parameters in generic classes, methods, functions and type aliases signatures.",
149+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/signatures/#show_signature_type_parameters",
150+
"type": "boolean",
151+
"default": true
152+
},
147153
"separate_signature": {
148154
"title": "Whether to put the whole signature in a code block below the heading. If a formatter (Black or Ruff) is installed, the signature is also formatted using it.",
149155
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/signatures/#separate_signature",
@@ -210,6 +216,12 @@
210216
"type": "boolean",
211217
"default": true
212218
},
219+
"show_docstring_type_parameters": {
220+
"title": "Whether to display the \"Type Parameters\" section in the object's docstring.",
221+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/docstrings/#show_docstring_type_parameters",
222+
"type": "boolean",
223+
"default": true
224+
},
213225
"show_docstring_warns": {
214226
"title": "Whether to display the \"Warns\" section in the object's docstring.",
215227
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/docstrings/#show_docstring_warns",
@@ -313,4 +325,4 @@
313325
}
314326
},
315327
"additionalProperties": false
316-
}
328+
}

docs/usage/configuration/docstrings.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,63 @@ class Class:
792792
////
793793
///
794794

795+
## `show_docstring_type_aliases`
796+
797+
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
798+
799+
Whether to render the "Type Aliases" sections of docstrings.
800+
801+
```yaml title="in mkdocs.yml (global configuration)"
802+
plugins:
803+
- mkdocstrings:
804+
handlers:
805+
python:
806+
options:
807+
show_docstring_type_aliases: true
808+
```
809+
810+
```md title="or in docs/some_page.md (local configuration)"
811+
::: path.to.module
812+
options:
813+
show_docstring_type_aliases: false
814+
```
815+
816+
```python
817+
"""Summary.
818+
819+
Type Aliases:
820+
TypeAlias: Some type alias.
821+
"""
822+
823+
824+
type TypeAlias = int
825+
"""Summary."""
826+
```
827+
828+
/// admonition | Preview
829+
type: preview
830+
831+
//// tab | With type_aliases
832+
<h2>module</h2>
833+
<p>Summary.</p>
834+
<p><b>Type Aliases:</b></p>
835+
836+
**Name** | **Description**
837+
------------ | ----------------
838+
`TypeAlias` | Some type alias.
839+
840+
<h3><code>TypeAlias</code></h3>
841+
<p>Summary.</p>
842+
////
843+
844+
//// tab | Without classes
845+
<h2>module</h2>
846+
<p>Summary.</p>
847+
<h3><code>TypeAlias</code></h3>
848+
<p>Summary.</p>
849+
////
850+
///
851+
795852
## `show_docstring_modules`
796853

797854
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
@@ -1225,6 +1282,56 @@ def rand() -> int:
12251282
////
12261283
///
12271284

1285+
## `show_docstring_type_parameters`
1286+
1287+
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1288+
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1289+
1290+
Whether to render the "Type Parameters" section of docstrings.
1291+
1292+
```yaml title="in mkdocs.yml (global configuration)"
1293+
plugins:
1294+
- mkdocstrings:
1295+
handlers:
1296+
python:
1297+
options:
1298+
show_docstring_type_parameters: true
1299+
```
1300+
1301+
```md title="or in docs/some_page.md (local configuration)"
1302+
::: path.to.module
1303+
options:
1304+
show_docstring_type_parameters: false
1305+
```
1306+
1307+
```python
1308+
class AClass[X: (int, str) = str]:
1309+
"""Represents something.
1310+
1311+
Type Parameters:
1312+
X: Something.
1313+
"""
1314+
```
1315+
1316+
/// admonition | Preview
1317+
type: preview
1318+
1319+
//// tab | With parameters
1320+
<h2><code>AClass</code></h2>
1321+
<p>Represents something.</p>
1322+
<p><b>Type Parameters:</b></p>
1323+
1324+
**Name** | **Bound or Constraints** | **Description** | **Default**
1325+
---------- | ------------------------ | --------------- | -----------
1326+
`whatever` | `(int, str)` | Something. | `str`
1327+
////
1328+
1329+
//// tab | Without parameters
1330+
<h2><code>AClass</code></h2>
1331+
<p>Represents something.</p>
1332+
////
1333+
///
1334+
12281335
## `show_docstring_warns`
12291336

12301337
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**

0 commit comments

Comments
 (0)