Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PEP 695 generics #221

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
"type": "boolean",
"default": false
},
"show_signature_type_parameters": {
"title": "Show the type parameters in generic classes, methods, functions and type aliases signatures.",
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/signatures/#show_signature_type_parameters",
"type": "boolean",
"default": true
},
"separate_signature": {
"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.",
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/signatures/#separate_signature",
Expand Down Expand Up @@ -210,6 +216,12 @@
"type": "boolean",
"default": true
},
"show_docstring_type_parameters": {
"title": "Whether to display the \"Type Parameters\" section in the object's docstring.",
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/docstrings/#show_docstring_type_parameters",
"type": "boolean",
"default": true
},
"show_docstring_warns": {
"title": "Whether to display the \"Warns\" section in the object's docstring.",
"markdownDescription": "https://mkdocstrings.github.io/python/usage/configuration/docstrings/#show_docstring_warns",
Expand Down Expand Up @@ -313,4 +325,4 @@
}
},
"additionalProperties": false
}
}
107 changes: 107 additions & 0 deletions docs/usage/configuration/docstrings.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,63 @@ class Class:
////
///

## `show_docstring_type_aliases`

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

Whether to render the "Type Aliases" sections of docstrings.

```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_docstring_type_aliases: true
```

```md title="or in docs/some_page.md (local configuration)"
::: path.to.module
options:
show_docstring_type_aliases: false
```

```python
"""Summary.

Type Aliases:
TypeAlias: Some type alias.
"""


type TypeAlias = int
"""Summary."""
```

/// admonition | Preview
type: preview

//// tab | With type_aliases
<h2>module</h2>
<p>Summary.</p>
<p><b>Type Aliases:</b></p>

**Name** | **Description**
------------ | ----------------
`TypeAlias` | Some type alias.

<h3><code>TypeAlias</code></h3>
<p>Summary.</p>
////

//// tab | Without classes
<h2>module</h2>
<p>Summary.</p>
<h3><code>TypeAlias</code></h3>
<p>Summary.</p>
////
///

## `show_docstring_modules`

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

## `show_docstring_type_parameters`

- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->

Whether to render the "Type Parameters" section of docstrings.

```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_docstring_type_parameters: true
```

```md title="or in docs/some_page.md (local configuration)"
::: path.to.module
options:
show_docstring_type_parameters: false
```

```python
class AClass[X: (int, str) = str]:
"""Represents something.

Type Parameters:
X: Something.
"""
```

/// admonition | Preview
type: preview

//// tab | With parameters
<h2><code>AClass</code></h2>
<p>Represents something.</p>
<p><b>Type Parameters:</b></p>

**Name** | **Bound or Constraints** | **Description** | **Default**
---------- | ------------------------ | --------------- | -----------
`whatever` | `(int, str)` | Something. | `str`
////

//// tab | Without parameters
<h2><code>AClass</code></h2>
<p>Represents something.</p>
////
///

## `show_docstring_warns`

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