diff --git a/docs/schema.json b/docs/schema.json index e1863d26..fc1d3467 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -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", @@ -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", @@ -313,4 +325,4 @@ } }, "additionalProperties": false -} \ No newline at end of file +} diff --git a/docs/usage/configuration/docstrings.md b/docs/usage/configuration/docstrings.md index 0cf2dac1..72036be3 100644 --- a/docs/usage/configuration/docstrings.md +++ b/docs/usage/configuration/docstrings.md @@ -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 +

module

+

Summary.

+

Type Aliases:

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

TypeAlias

+

Summary.

+//// + +//// tab | Without classes +

module

+

Summary.

+

TypeAlias

+

Summary.

+//// +/// + ## `show_docstring_modules` - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** @@ -1225,6 +1282,56 @@ def rand() -> int: //// /// +## `show_docstring_type_parameters` + +- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** + + +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 +

AClass

+

Represents something.

+

Type Parameters:

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

AClass

+

Represents something.

+//// +/// + ## `show_docstring_warns` - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }** diff --git a/docs/usage/configuration/headings.md b/docs/usage/configuration/headings.md index 467779e4..511650ff 100644 --- a/docs/usage/configuration/headings.md +++ b/docs/usage/configuration/headings.md @@ -179,6 +179,285 @@ To customize symbols, see [Customizing symbol types](../customization.md/#symbol /// +## `type_parameter_headings` + +- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** + +Whether to render headings for generic class, function/method and type alias +type parameters. + +With this option enabled, each type parameter of a generic object (including +type parameters of `__init__` methods merged in their parent class with the +[`merge_init_into_class`][] option) gets a permalink, an entry in the Table of +Contents, and an entry in the generated objects inventory. The permalink and +inventory entry allow cross-references from internal and external pages. + +The identifier used in the permalink and inventory is of the following form: +`path.to.function:type_param_name`. To manually cross-reference a parameter, +you can therefore use this Markdown syntax: + +```md +- Class type parameter: [`Param`][package.module.Class:Param] +- Method type parameter: [`Param`][package.module.Class.method:Param] +- Function type parameter: [`Param`][package.module.function:Param] +- Type alias type parameter: [`Param`][package.module.TypeAlias:Param] +- Type variable tuple: [`*Args`][package.module.function:*Args] +- Parameter specification: [`**Params`][package.module.function:**Params] +``` + +Enabling this option along with [`signature_crossrefs`][] will automatically +render cross-references to type parameters in class/function/method/type alias +signatures. + +```yaml title="in mkdocs.yml (global configuration)" +plugins: +- mkdocstrings: + handlers: + python: + options: + type_parameter_headings: false +``` + +```md title="or in docs/some_page.md (local configuration)" +::: path.to.module + options: + type_parameter_headings: true +``` + +/// admonition | Preview: Cross-references + type: preview + +
+

+ set_element + ¤ +

+
+
set_element[T](element: T) -> None
+
+
+
+

Set element.

+

Parameters:

+ +

Type Parameters:

+ +
+
+ +/// + +/// admonition | Preview: Type parameters sections + type: preview + +//// tab | Table style +
+
+

Parameters:

+
+
+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
+

+ element + ¤ +

+
+ T + +
+

The element to set.

+
+
+ required +
+
+
+

Type Parameters:

+
+
+ + + + + + + + + + + + + + + + + +
NameBound or ConstraintsDescriptionDefault
+

T + ¤ +

+
+ +
+

The type of the element.

+
+
+ required +
+
+
+
+
+//// + +//// tab | List style +
+
+

Parameters:

+ +

Type Parameters:

+ +
+
+//// + +//// tab | Spacy style +
+
+
+
+ + + + + + + + + + + + + +
PARAMETERDESCRIPTION
+

+ element + ¤ +

+
+
+

The element to set.

+
+

+ + TYPE: + T + +

+
+
+
+
+
+ + + + + + + + + + + + + +
TYPE PARAMETERDESCRIPTION
+

T + ¤ +

+
+
+

The type of the element.

+
+

+

+
+
+
+
+
+//// +/// + +/// admonition | Preview: Table of contents (with symbol types) + type: preview + + set_element
+ T + +To customize symbols, see [Customizing symbol types](../customization.md/#symbol-types). + +/// + ## `show_root_heading` - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** @@ -286,15 +565,15 @@ More text. type: preview //// tab | With ToC entry -**Table of contents** -[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" } -[`object`](#permalink-to-object){ title="#permalink-to-object" } -[Other heading](#permalink-to-other-heading){ title="#permalink-to-other-heading" } +**Table of contents** +[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" } +[`object`](#permalink-to-object){ title="#permalink-to-object" } +[Other heading](#permalink-to-other-heading){ title="#permalink-to-other-heading" } //// //// tab | Without ToC entry -**Table of contents** -[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" } +**Table of contents** +[Some heading](#permalink-to-some-heading){ title="#permalink-to-some-heading" } [Other heading](#permalink-to-other-heading){ title="#permalink-to-other-heading" } //// /// @@ -400,7 +679,7 @@ plugins: Show the full Python path of every object. Same as for [`show_root_members_full_path`][], -but for every member, recursively. This option takes precedence over +but for every member, recursively. This option takes precedence over [`show_root_members_full_path`][]: `show_root_members_full_path` | `show_object_full_path` | Direct root members path @@ -454,7 +733,7 @@ When [grouped by categories][group_by_category], show a heading for each categor These category headings will appear in the table of contents, allowing you to link to them using their permalinks. -WARNING: **Not recommended with deeply nested object** +WARNING: **Not recommended with deeply nested object** When injecting documentation for deeply nested objects, you'll quickly run out of heading levels, and the objects at the bottom of the tree risk all getting documented diff --git a/docs/usage/configuration/members.md b/docs/usage/configuration/members.md index 220a26fe..aa8b9f41 100644 --- a/docs/usage/configuration/members.md +++ b/docs/usage/configuration/members.md @@ -560,7 +560,7 @@ package Whether to render summaries of modules, classes, functions (methods) and attributes. This option accepts a boolean (`yes`, `true`, `no`, `false` in YAML) -or a dictionary with one or more of the following keys: `attributes`, `functions`, `classes`, `modules`, +or a dictionary with one or more of the following keys: `attributes`, `functions`, `classes`, `modules`, `type_aliases`, with booleans as values. Class methods summary is (de)activated with the `functions` key. By default, `summary` is false, and by extension all values are false. diff --git a/docs/usage/configuration/signatures.md b/docs/usage/configuration/signatures.md index 879db6b1..df32f505 100644 --- a/docs/usage/configuration/signatures.md +++ b/docs/usage/configuration/signatures.md @@ -202,7 +202,7 @@ plugins: [:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } — [:octicons-tag-24: Insiders 1.8.0](../../insiders/changelog.md#1.8.0) — -**This feature also requires +**This feature also requires [Griffe Insiders](https://mkdocstrings.github.io/griffe/insiders/) to be installed.** @@ -377,6 +377,60 @@ function(param1, param2=None) //// /// +## `show_signature_type_parameters` + +- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** + + +Show the type parameters in generic classes, methods, functions and type aliases +signatures. + +Since the heading can become quite long when type parameters are rendered, it is +usually best to [separate the signature][separate_signature] from the heading. + +```yaml title="in mkdocs.yml (global configuration)" +plugins: +- mkdocstrings: + handlers: + python: + options: + separate_signature: true + show_signature_annotations: true + show_signature_type_parameters: true +``` + +```md title="or in docs/some_page.md (local configuration)" +::: path.to.module + options: + separate_signature: true + show_signature_annotations: true + show_signature_type_parameters: false +``` + +/// admonition | Preview + type: preview + +//// tab | With signature type parameters +

function

+ +```python +function[T, *R](param: T) -> tuple[*R] +``` + +

Function docstring.

+//// + +//// tab | Without signature type parameters +

function

+ +```python +function(param: T) -> tuple[*R] +``` + +

Function docstring.

+//// +/// + ## `separate_signature` - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }** diff --git a/docs/usage/customization.md b/docs/usage/customization.md index 907809c8..7f9dc2c6 100644 --- a/docs/usage/customization.md +++ b/docs/usage/customization.md @@ -34,9 +34,10 @@ The following CSS classes are used in the generated HTML: - `doc-class`: on `div`s containing a class - `doc-function`: on `div`s containing a function - `doc-module`: on `div`s containing a module + - `doc-type_alias`: on `div`s containing a type alias - `doc-heading`: on objects headings - `doc-object-name`: on `span`s wrapping objects names/paths in the heading - - `doc-KIND-name`: as above, specific to the kind of object (module, class, function, attribute) + - `doc-KIND-name`: as above, specific to the kind of object (module, class, function, attribute, type_alias) - `doc-contents`: on `div`s wrapping the docstring then the children (if any) - `first`: same, but only on the root object's contents `div` - `doc-labels`: on `span`s wrapping the object's labels @@ -48,7 +49,7 @@ The following CSS classes are used in the generated HTML: - `doc-symbol`: on `code` tags of symbol types - `doc-symbol-heading`: on symbol types in headings - `doc-symbol-toc`: on symbol types in the ToC - - `doc-symbol-KIND`: specific to the kind of object (`module`, `class`, `function`, `method`, `attribute`) + - `doc-symbol-KIND`: specific to the kind of object (`module`, `class`, `function`, `method`, `attribute`, `type_alias`) /// admonition | Example with colorful labels type: example @@ -90,33 +91,41 @@ by overriding the values of our CSS variables, for example: ```css title="docs/css/mkdocstrings.css" [data-md-color-scheme="default"] { --doc-symbol-parameter-fg-color: #df50af; + --doc-symbol-type_parameter-fg-color: #df50af; --doc-symbol-attribute-fg-color: #0079ff; --doc-symbol-function-fg-color: #00dfa2; --doc-symbol-method-fg-color: #00dfa2; --doc-symbol-class-fg-color: #d1b619; + --doc-symbol-type_alias-fg-color: #d1b619; --doc-symbol-module-fg-color: #ff0060; --doc-symbol-parameter-bg-color: #df50af1a; + --doc-symbol-type_parameter-bg-color: #df50af1a; --doc-symbol-attribute-bg-color: #0079ff1a; --doc-symbol-function-bg-color: #00dfa21a; --doc-symbol-method-bg-color: #00dfa21a; --doc-symbol-class-bg-color: #d1b6191a; + --doc-symbol-type_alias-bg-color: #d1b6191a; --doc-symbol-module-bg-color: #ff00601a; } [data-md-color-scheme="slate"] { --doc-symbol-parameter-fg-color: #ffa8cc; + --doc-symbol-type_parameter-fg-color: #ffa8cc; --doc-symbol-attribute-fg-color: #963fb8; --doc-symbol-function-fg-color: #6d67e4; --doc-symbol-method-fg-color: #6d67e4; --doc-symbol-class-fg-color: #46c2cb; + --doc-symbol-type_alias-fg-color: #46c2cb; --doc-symbol-module-fg-color: #f2f7a1; --doc-symbol-parameter-bg-color: #ffa8cc1a; + --doc-symbol-type_parameter-bg-color: #ffa8cc1a; --doc-symbol-attribute-bg-color: #963fb81a; --doc-symbol-function-bg-color: #6d67e41a; --doc-symbol-method-bg-color: #6d67e41a; --doc-symbol-class-bg-color: #46c2cb1a; + --doc-symbol-type_alias-bg-color: #46c2cb1a; --doc-symbol-module-bg-color: #f2f7a11a; } ``` @@ -129,17 +138,21 @@ otherwise just override the variables at root level: ```css title="docs/css/mkdocstrings.css" :root { --doc-symbol-parameter-fg-color: #df50af; + --doc-symbol-type_parameter-fg-color: #df50af; --doc-symbol-attribute-fg-color: #0079ff; --doc-symbol-function-fg-color: #00dfa2; --doc-symbol-method-fg-color: #00dfa2; --doc-symbol-class-fg-color: #d1b619; + --doc-symbol-type_alias-fg-color: #d1b619; --doc-symbol-module-fg-color: #ff0060; --doc-symbol-parameter-bg-color: #df50af1a; + --doc-symbol-type_parameter-bg-color: #df50af1a; --doc-symbol-attribute-bg-color: #0079ff1a; --doc-symbol-function-bg-color: #00dfa21a; --doc-symbol-method-bg-color: #00dfa21a; --doc-symbol-class-bg-color: #d1b6191a; + --doc-symbol-type_alias-bg-color: #d1b6191a; --doc-symbol-module-bg-color: #ff00601a; } ``` @@ -151,33 +164,41 @@ otherwise just override the variables at root level: @@ -204,6 +225,10 @@ For example, to use single letters instead of truncated types: content: "P"; } +.doc-symbol-type_parameter::after { + content: "P"; +} + .doc-symbol-attribute::after { content: "A"; } @@ -220,6 +245,10 @@ For example, to use single letters instead of truncated types: content: "C"; } +.doc-symbol-type_alias::after { + content: "T"; +} + .doc-symbol-module::after { content: "M"; } @@ -234,6 +263,10 @@ For example, to use single letters instead of truncated types: content: "P"; } + #preview-symbol-names .doc-symbol-type_parameter::after { + content: "P"; + } + #preview-symbol-names .doc-symbol-attribute::after { content: "A"; } @@ -250,16 +283,23 @@ For example, to use single letters instead of truncated types: content: "C"; } + #preview-symbol-names .doc-symbol-type_alias::after { + content: "T"; + } + + #preview-symbol-names .doc-symbol-module::after { content: "M"; } @@ -324,6 +364,19 @@ Available context: - `config`: The handler configuration (dictionary). - `module`: The [Module][griffe.Module] instance. +#### `type_alias.html` + +- `heading`: The class heading. +- `labels`: The class labels. +- `signature`: The class signature. +- `contents`: The class contents: bases, docstring, source and children blocks. +- `docstring`: The class docstring. + +Available context: + +- `config`: The handler configuration (dictionary). +- `type_alias`: The [TypeAlias][griffe.TypeAlias] instance. + #### `class.html` - `heading`: The class heading. @@ -371,9 +424,11 @@ Available context: #### Docstring sections In `docstring/attributes.html`, -`docstring/functions.html`, -`docstring/classes.html`, -`docstring/modules.html`, +`docstring/functions.html`, +`docstring/classes.html`, +`docstring/type_aliases.html`, +`docstring/modules.html`, +`docstring/type_parameters.html`, `docstring/other_parameters.html`, `docstring/parameters.html`, `docstring/raises.html`, @@ -439,4 +494,4 @@ div.doc-contents:not(.first) { padding-left: 25px; border-left: .05rem solid rgba(200, 200, 200, 0.2); } -``` \ No newline at end of file +``` diff --git a/mkdocs.yml b/mkdocs.yml index 2d546126..91ec6e19 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -165,6 +165,7 @@ plugins: inherited_members: true merge_init_into_class: true parameter_headings: true + type_parameter_headings: true preload_modules: [mkdocstrings] relative_crossrefs: true scoped_crossrefs: true @@ -174,6 +175,7 @@ plugins: show_root_heading: true show_root_full_path: false show_signature_annotations: true + show_signature_type_parameters: true show_source: false show_symbol_type_heading: true show_symbol_type_toc: true diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 4171fd76..7e021aac 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -83,6 +83,7 @@ class PythonHandler(BaseHandler): "show_if_no_docstring": False, "show_signature": True, "show_signature_annotations": False, + "show_signature_type_parameters": True, "signature_crossrefs": False, "separate_signature": False, "line_length": 60, @@ -92,6 +93,7 @@ class PythonHandler(BaseHandler): "show_docstring_attributes": True, "show_docstring_functions": True, "show_docstring_classes": True, + "show_docstring_type_aliases": True, "show_docstring_modules": True, "show_docstring_description": True, "show_docstring_examples": True, @@ -100,6 +102,7 @@ class PythonHandler(BaseHandler): "show_docstring_raises": True, "show_docstring_receives": True, "show_docstring_returns": True, + "show_docstring_type_parameters": True, "show_docstring_warns": True, "show_docstring_yields": True, "show_source": True, @@ -120,6 +123,7 @@ class PythonHandler(BaseHandler): "show_labels": True, "unwrap_annotated": False, "parameter_headings": False, + "type_parameter_headings": False, "modernize_annotations": False, } """Default handler configuration. @@ -143,6 +147,7 @@ class PythonHandler(BaseHandler): Attributes: Headings options: heading_level (int): The initial heading level to use. Default: `2`. parameter_headings (bool): Whether to render headings for parameters (therefore showing parameters in the ToC). Default: `False`. + type_parameter_headings (bool): Whether to render headings for type parameters (therefore showing type parameters in the ToC). Default: `False`. show_root_heading (bool): Show the heading of the object at the root of the documentation tree (i.e. the object referenced by the identifier after `:::`). Default: `False`. show_root_toc_entry (bool): If the root heading is not shown, at least add a ToC entry for it. Default: `True`. @@ -169,7 +174,7 @@ class PythonHandler(BaseHandler): to lower members in the hierarchy). Default: `["!^_[^_]"]`. group_by_category (bool): Group the object's children by categories: attributes, classes, functions, and modules. Default: `True`. show_submodules (bool): When rendering a module, show its submodules recursively. Default: `False`. - summary (bool | dict[str, bool]): Whether to render summaries of modules, classes, functions (methods) and attributes. + summary (bool | dict[str, bool]): Whether to render summaries of modules, classes, functions (methods), attributes and type aliases. show_labels (bool): Whether to show labels of the members. Default: `True`. Attributes: Docstrings options: @@ -183,6 +188,7 @@ class PythonHandler(BaseHandler): show_docstring_attributes (bool): Whether to display the "Attributes" section in the object's docstring. Default: `True`. show_docstring_functions (bool): Whether to display the "Functions" or "Methods" sections in the object's docstring. Default: `True`. show_docstring_classes (bool): Whether to display the "Classes" section in the object's docstring. Default: `True`. + show_docstring_type_aliases (bool): Whether to display the "Type Aliases" section in the object's docstring. Default: `True`. show_docstring_modules (bool): Whether to display the "Modules" section in the object's docstring. Default: `True`. show_docstring_description (bool): Whether to display the textual block (including admonitions) in the object's docstring. Default: `True`. show_docstring_examples (bool): Whether to display the "Examples" section in the object's docstring. Default: `True`. @@ -191,6 +197,7 @@ class PythonHandler(BaseHandler): show_docstring_raises (bool): Whether to display the "Raises" section in the object's docstring. Default: `True`. show_docstring_receives (bool): Whether to display the "Receives" section in the object's docstring. Default: `True`. show_docstring_returns (bool): Whether to display the "Returns" section in the object's docstring. Default: `True`. + show_docstring_type_parameters (bool): Whether to display the "Type Parameters" section in the object's docstring. Default: `True`. show_docstring_warns (bool): Whether to display the "Warns" section in the object's docstring. Default: `True`. show_docstring_yields (bool): Whether to display the "Yields" section in the object's docstring. Default: `True`. @@ -199,6 +206,7 @@ class PythonHandler(BaseHandler): line_length (int): Maximum line length when formatting code/signatures. Default: `60`. show_signature (bool): Show methods and functions signatures. Default: `True`. show_signature_annotations (bool): Show the type annotations in methods and functions signatures. Default: `False`. + show_signature_type_parameters (bool): Show the type parameters in generic classes, methods, functions and type aliases signatures. Default: `True`. signature_crossrefs (bool): Whether to render cross-references for type annotations in signatures. Default: `False`. separate_signature (bool): 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. Default: `False`. @@ -387,6 +395,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa "functions": True, "classes": True, "modules": True, + "type_aliases": True, } elif summary is False: final_config["summary"] = { @@ -394,6 +403,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa "functions": False, "classes": False, "modules": False, + "type_aliases": False, } else: final_config["summary"] = { @@ -401,6 +411,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa "functions": summary.get("functions", False), "classes": summary.get("classes", False), "modules": summary.get("modules", False), + "type_aliases": summary.get("type_aliases", False), } return template.render( @@ -430,13 +441,17 @@ def update_env(self, md: Markdown, config: dict) -> None: self.env.filters["order_members"] = rendering.do_order_members self.env.filters["format_code"] = rendering.do_format_code self.env.filters["format_signature"] = rendering.do_format_signature + self.env.filters["format_class"] = rendering.do_format_class + self.env.filters["format_merged_init"] = rendering.do_format_merged_init self.env.filters["format_attribute"] = rendering.do_format_attribute + self.env.filters["format_type_alias"] = rendering.do_format_type_alias self.env.filters["filter_objects"] = rendering.do_filter_objects self.env.filters["stash_crossref"] = rendering.do_stash_crossref self.env.filters["get_template"] = rendering.do_get_template self.env.filters["as_attributes_section"] = rendering.do_as_attributes_section self.env.filters["as_functions_section"] = rendering.do_as_functions_section self.env.filters["as_classes_section"] = rendering.do_as_classes_section + self.env.filters["as_type_aliases_section"] = rendering.do_as_type_aliases_section self.env.filters["as_modules_section"] = rendering.do_as_modules_section self.env.globals["AutorefsHook"] = rendering.AutorefsHook self.env.tests["existing_template"] = lambda template_name: template_name in self.env.list_templates() diff --git a/src/mkdocstrings_handlers/python/rendering.py b/src/mkdocstrings_handlers/python/rendering.py index 085f0c34..d08c6735 100644 --- a/src/mkdocstrings_handlers/python/rendering.py +++ b/src/mkdocstrings_handlers/python/rendering.py @@ -24,6 +24,8 @@ DocstringSectionClasses, DocstringSectionFunctions, DocstringSectionModules, + DocstringSectionTypeAliases, + DocstringTypeAlias, Object, ) from jinja2 import TemplateNotFound, pass_context, pass_environment @@ -34,7 +36,7 @@ if TYPE_CHECKING: from collections.abc import Sequence - from griffe import Attribute, Class, Function, Module + from griffe import Attribute, Class, Function, Module, TypeAlias from jinja2 import Environment, Template from jinja2.runtime import Context from mkdocstrings.handlers.base import CollectorItem @@ -110,7 +112,7 @@ def __call__(self, crossref: str, *, length: int) -> str: do_stash_crossref = _StashCrossRefFilter() -def _format_signature(name: Markup, signature: str, line_length: int) -> str: +def _format_signature(name: Markup, signature: str, prefix: str, line_length: int) -> str: name = str(name).strip() # type: ignore[assignment] signature = signature.strip() if len(name + signature) < line_length: @@ -118,14 +120,14 @@ def _format_signature(name: Markup, signature: str, line_length: int) -> str: # Black cannot format names with dots, so we replace # the whole name with a string of equal length - name_length = len(name) + name_length = max(len(name) - len(prefix) - 1, 1) formatter = _get_formatter() - formatable = f"def {'x' * name_length}{signature}: pass" + formatable = f"{prefix} {'x' * name_length}{signature}: pass" formatted = formatter(formatable, line_length) # We put back the original name # and remove starting `def ` and trailing `: pass` - return name + formatted[4:-5].strip()[name_length:-1] + return name + formatted[len(prefix) + 1 : -5].strip()[name_length:-1] @pass_context @@ -153,7 +155,8 @@ def do_format_signature( """ env = context.environment # TODO: Stop using `do_get_template` when `*.html` templates are removed. - template = env.get_template(do_get_template(env, "signature")) + type_params_template = env.get_template(do_get_template(env, "type_parameters")) + signature_template = env.get_template(do_get_template(env, "signature")) if annotations is None: new_context = context.parent @@ -162,8 +165,10 @@ def do_format_signature( new_context["config"] = dict(new_context["config"]) new_context["config"]["show_signature_annotations"] = annotations - signature = template.render(new_context, function=function, signature=True) - signature = _format_signature(callable_path, signature, line_length) + signature = type_params_template.render(context.parent, obj=function, signature=True) + signature += signature_template.render(new_context, function=function, signature=True) + + signature = _format_signature(callable_path, signature, "def", line_length) signature = str( env.filters["highlight"]( Markup.escape(signature), @@ -191,6 +196,152 @@ def do_format_signature( return signature +@pass_context +def do_format_class( + context: Context, + class_path: Markup, + class_: Class, + line_length: int, + *, + crossrefs: bool = False, # noqa: ARG001 +) -> str: + """Format a class. + + Parameters: + context: Jinja context, passed automatically. + class_path: The path of the class we render the signature of. + class_: The class we render the signature of. + line_length: The line length. + crossrefs: Whether to cross-reference types in the signature. + + Returns: + The same code, formatted. + """ + env = context.environment + # TODO: Stop using `do_get_template` when `*.html` templates are removed. + template = env.get_template(do_get_template(env, "type_parameters")) + + signature = template.render(context.parent, obj=class_, signature=True) + + signature = _format_signature(class_path, signature, "class", line_length) + signature = str( + env.filters["highlight"]( + Markup.escape(signature), + language="python", + inline=False, + classes=["doc-signature"], + linenums=False, + ), + ) + + # Since we highlight the signature without `class`, + # Pygments does not see a class definition. + # The result is that the class name is not parsed as such, + # but instead as a regular name: `n` CSS class instead of `nc`. + # To fix it, we replace the first occurrence of an `n` CSS class + # with an `nc` one, unless we found `nc` already. + if signature.find('class="nc"') == -1: + signature = signature.replace('class="n"', 'class="nc"', 1) + + if stash := env.filters["stash_crossref"].stash: + for key, value in stash.items(): + signature = re.sub(rf"\b{key}\b", value, signature) + stash.clear() + + return signature + + +@pass_context +def do_format_merged_init( + context: Context, + class_path: Markup, + init: Function, + line_length: int, + *, + init_as_method: bool = False, + annotations: bool | None = None, + crossrefs: bool = False, # noqa: ARG001 +) -> str: + """Format a signature of an `__init__` method merged into a class. + + Parameters: + context: Jinja context, passed automatically. + class_path: The path of the class we render the signature of. + init: The method we render the signature of. + line_length: The line length. + init_as_method: Whether to show `__init__` as a method, instead of merging its + (type) parameters into the signature of the class. + annotations: Whether to show type annotations. + crossrefs: Whether to cross-reference types in the signature. + + Returns: + The same code, formatted. + """ + env = context.environment + # TODO: Stop using `do_get_template` when `*.html` templates are removed. + type_params_template = env.get_template(do_get_template(env, "type_parameters")) + signature_template = env.get_template(do_get_template(env, "signature")) + + if annotations is None: + signature_context = context.parent + else: + signature_context = dict(context.parent) + signature_context["config"] = dict(signature_context["config"]) + signature_context["config"]["show_signature_annotations"] = annotations + + class_signature = type_params_template.render(context.parent, obj=init.parent, signature=True) + + init_signature = signature_template.render(signature_context, function=init, signature=True) + if init_as_method: + init_signature = type_params_template.render(signature_context, obj=init, signature=True) + init_signature + + name = str(class_path).strip() + if len(name + class_signature + ".__init__" + init_signature) < line_length: + signature = name + class_signature + ".__init__" + init_signature + else: + formatter = _get_formatter() + + # Black cannot format names with dots, so we replace + # the whole name with a string of equal length + name_length = max(len(name) - 6, 1) + formatted_class_signature = formatter(f"class {'x' * name_length}{class_signature}: pass", line_length) + formatted_class_signature = formatted_class_signature[6:-5].strip()[name_length:] + + name_length = len(formatted_class_signature.splitlines()[-1]) + len(".__init__") - 4 + formatted_init_signature = formatter(f"def {'x' * name_length}{init_signature}: pass", line_length) + formatted_init_signature = formatted_init_signature[4:-5].strip()[name_length:] + + signature = name + formatted_class_signature + ".__init__" + formatted_init_signature + else: + signature = _format_signature(class_path, class_signature + init_signature, "def", line_length) + + signature = str( + env.filters["highlight"]( + Markup.escape(signature), + language="python", + inline=False, + classes=["doc-signature"], + linenums=False, + ), + ) + + # Since we highlight the signature without `class`, + # Pygments does not see a class definition. + # The result is that the class name is not parsed as such, + # but instead as a regular name: `n` CSS class instead of `nc`. + # To fix it, we replace the first occurrence of an `n` CSS class + # with an `nc` one, unless we found `nc` already. + if signature.find('class="nc"') == -1: + signature = signature.replace('class="n"', 'class="nc"', 1) + + if stash := env.filters["stash_crossref"].stash: + for key, value in stash.items(): + signature = re.sub(rf"\b{key}\b", value, signature) + stash.clear() + + return signature + + @pass_context def do_format_attribute( context: Context, @@ -244,6 +395,66 @@ def do_format_attribute( return signature +@pass_context +def do_format_type_alias( + context: Context, + type_alias_path: Markup, + type_alias: TypeAlias, + line_length: int, + *, + crossrefs: bool = False, # noqa: ARG001 +) -> str: + """Format a type alias. + + Parameters: + context: Jinja context, passed automatically. + type_alias_path: The path of the type alias we render the signature of. + type_alias: The type alias we render the signature of. + line_length: The line length. + crossrefs: Whether to cross-reference types in the signature. + + Returns: + The same code, formatted. + """ + env = context.environment + # TODO: Stop using `do_get_template` when `*.html` templates are removed. + type_params_template = env.get_template(do_get_template(env, "type_parameters")) + expr_template = env.get_template(do_get_template(env, "expression")) + + signature = str(type_alias_path).strip() + signature += type_params_template.render(context.parent, obj=type_alias, signature=True) + value = expr_template.render(context.parent, expression=type_alias.value, signature=True) + signature += f" = {value}" + + signature = do_format_code(signature, line_length) + signature = str( + env.filters["highlight"]( + Markup.escape(signature), + language="python", + inline=False, + classes=["doc-signature"], + linenums=False, + ), + ) + + # Since we highlight the signature without `type`, + # Pygments sees only an assignment, not a type alias definition. + # (At the moment it does not understand type alias definitions anyway) + # The result is that the type alias name is not parsed as such, + # but instead as a regular name: `n` CSS class instead of `nc`. + # To fix it, we replace the first occurrence of an `n` CSS class + # with an `nc` one, unless we found `nc` already. + if signature.find('class="nc"') == -1: + signature = signature.replace('class="n"', 'class="nc"', 1) + + if stash := env.filters["stash_crossref"].stash: + for key, value in stash.items(): + signature = re.sub(rf"\b{key}\b", value, signature) + stash.clear() + + return signature + + def do_order_members( members: Sequence[Object | Alias], order: Order, @@ -515,7 +726,7 @@ def do_get_template(env: Environment, obj: str | Object) -> str | Template: extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {}) if name := extra_data.get("template", ""): return name - name = obj.kind.value + name = obj.kind.value.replace(" ", "_") try: template = env.get_template(f"{name}.html") except TemplateNotFound: @@ -554,7 +765,7 @@ def do_as_attributes_section( name=attribute.name, description=attribute.docstring.value.split("\n", 1)[0] if attribute.docstring else "", annotation=attribute.annotation, - value=attribute.value, # type: ignore[arg-type] + value=attribute.value, ) for attribute in attributes if not check_public or attribute.is_public @@ -619,6 +830,34 @@ def do_as_classes_section( ) +@pass_context +def do_as_type_aliases_section( + context: Context, # noqa: ARG001 + type_aliases: Sequence[TypeAlias], + *, + check_public: bool = True, +) -> DocstringSectionTypeAliases: + """Build a type aliases section from a list of type aliases. + + Parameters: + type_aliases: The type aliases to build the section from. + check_public: Whether to check if the type_alias is public. + + Returns: + A type aliases docstring section. + """ + return DocstringSectionTypeAliases( + [ + DocstringTypeAlias( + name=type_alias.name, + description=type_alias.docstring.value.split("\n", 1)[0] if type_alias.docstring else "", + ) + for type_alias in type_aliases + if not check_public or type_alias.is_public + ], + ) + + @pass_context def do_as_modules_section( context: Context, # noqa: ARG001 @@ -691,8 +930,8 @@ def get_context(self) -> AutorefsHookInterface.Context: }.get(self.current_object.kind.value.lower(), "obj") origin = self.current_object.path try: - filepath = self.current_object.docstring.parent.filepath # type: ignore[union-attr] - lineno = self.current_object.docstring.lineno or 0 # type: ignore[union-attr] + filepath = self.current_object.docstring.parent.filepath + lineno = self.current_object.docstring.lineno or 0 except AttributeError: filepath = self.current_object.filepath lineno = 0 diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja index c9c23156..18469f0f 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/children.html.jinja @@ -13,7 +13,7 @@ Context: {% if obj.all_members %} {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {{ log.debug("Rendering children of " + obj.path) }} @@ -57,6 +57,26 @@ Context: {% endif %} {% endwith %} + {% with type_aliases = obj.type_aliases|filter_objects( + filters=config.filters, + members_list=members_list, + inherited_members=config.inherited_members, + keep_no_docstrings=config.show_if_no_docstring, + ) %} + {% if type_aliases %} + {% if config.show_category_heading %} + {% filter heading(heading_level, id=html_id ~ "-type_aliases") %}Type Aliases{% endfilter %} + {% endif %} + {% with heading_level = heading_level + extra_level %} + {% for type_alias in type_aliases|order_members(config.members_order, members_list) %} + {% if members_list is not none or (not type_alias.is_imported or type_alias.is_public) %} + {% include type_alias|get_template with context %} + {% endif %} + {% endfor %} + {% endwith %} + {% endif %} + {% endwith %} + {% with classes = obj.classes|filter_objects( filters=config.filters, members_list=members_list, @@ -143,6 +163,11 @@ Context: {% include attribute|get_template with context %} {% endwith %} + {% elif child.is_type_alias %} + {% with type_alias = child %} + {% include type_alias|get_template with context %} + {% endwith %} + {% elif child.is_class %} {% with class = child %} {% include class|get_template with context %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja index ff5e51c9..a5437ec8 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/class.html.jinja @@ -11,7 +11,7 @@ Context: {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {{ log.debug("Rendering " + class.path) }} @@ -43,7 +43,7 @@ Context: {% block heading scoped %} {#- Heading block. - + This block renders the heading for the class. -#} {% if config.show_symbol_type_heading %}{% endif %} @@ -52,17 +52,27 @@ Context: {% elif config.merge_init_into_class and "__init__" in all_members %} {% with function = all_members["__init__"] %} {%+ filter highlight(language="python", inline=True) %} - {{ class_name }}{% include "signature"|get_template with context %} + {{ class_name -}} + {%- include "type_parameters"|get_template with context -%} + {%- if function.is_generic and config.show_signature_annotations and config.show_signature_type_parameters -%} + {%- with obj = function -%} + .__init__ + {%- include "type_parameters"|get_template with context -%} + {%- endwith -%} + {%- endif -%} + {%- include "signature"|get_template with context -%} {% endfilter %} {% endwith %} {% else %} - {{ class_name }} + {%+ filter highlight(language="python", inline=True) %} + {{ class_name }}{% include "type_parameters"|get_template with context %} + {% endfilter %} {% endif %} {% endblock heading %} {% block labels scoped %} {#- Labels block. - + This block renders the labels for the class. -#} {% with labels = class.labels %} @@ -74,30 +84,39 @@ Context: {% block signature scoped %} {#- Signature block. - + This block renders the signature for the class. Overloads of the `__init__` method are rendered if `merge_init_into_class` is enabled. The actual `__init__` method signature is only rendered if `separate_signature` is also enabled. + + If the class is generic, but the `__init__` method isn't or `merge_init_into_class` is disabled, + the class signature is rendered if `separate_signature` and `show_signature_type_parameters` are enabled. + + If the `__init__` method or any overloads are generic, they are rendered as methods if + `merge_init_into_class`, `separate_signature` and `show_signature_type_parameters` are enabled. -#} - {% if config.merge_init_into_class %} - {% if "__init__" in all_members %} - {% with function = all_members["__init__"] %} - {% if function.overloads %} -
- {% for overload in function.overloads %} - {% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %} - {{ class.name }} - {% endfilter %} - {% endfor %} -
- {% endif %} - {% if config.separate_signature %} - {% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %} - {{ class.name }} - {% endfilter %} - {% endif %} - {% endwith %} - {% endif %} + {% if config.merge_init_into_class and "__init__" in all_members %} + {% with function = all_members["__init__"] %} + {% set init_as_method = config.show_signature_type_parameters and (function.is_generic and config.show_signature_annotations) or (function.overloads and function.overloads|selectattr("is_generic")|list|length) %} + {% if function.overloads %} +
+ {% for overload in function.overloads %} + {% filter format_merged_init(overload, config.line_length, init_as_method=init_as_method, annotations=True, crossrefs=config.signature_crossrefs) %} + {{ class.name }} + {% endfilter %} + {% endfor %} +
+ {% endif %} + {% if config.separate_signature %} + {% filter format_merged_init(function, config.line_length, init_as_method=init_as_method, crossrefs=config.signature_crossrefs) %} + {{ class.name }} + {% endfilter %} + {% endif %} + {% endwith %} + {% elif config.separate_signature and config.show_signature_type_parameters and class.is_generic %} + {% filter format_class(class, config.line_length, crossrefs=config.signature_crossrefs) %} + {{ class.name }} + {% endfilter %} {% endif %} {% endblock signature %} @@ -117,14 +136,14 @@ Context:
{% block contents scoped %} {#- Contents block. - + This block renders the contents of the class. It contains other blocks that users can override. Overriding the contents block allows to rearrange the order of the blocks. -#} {% block bases scoped %} {#- Class bases block. - + This block renders the bases for the class. -#} {% if config.show_bases and class.bases %} @@ -138,7 +157,7 @@ Context: {% block docstring scoped %} {#- Docstring block. - + This block renders the docstring for the class. -#} {% with docstring_sections = class.docstring.parsed %} @@ -161,7 +180,7 @@ Context: {% block summary scoped %} {#- Summary block. - + This block renders auto-summaries for classes, methods, and attributes. -#} {% include "summary"|get_template with context %} @@ -169,7 +188,7 @@ Context: {% block source scoped %} {#- Source block. - + This block renders the source code for the class. -#} {% if config.show_source %} @@ -205,7 +224,7 @@ Context: {% block children scoped %} {#- Children block. - + This block renders the children (members) of the class. -#} {% set root = False %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja index 14d11d03..d3404693 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja @@ -14,7 +14,7 @@ Context: {% if docstring_sections %} {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {{ log.debug("Rendering docstring") }} @@ -29,8 +29,12 @@ Context: {% include "docstring/functions"|get_template with context %} {% elif config.show_docstring_classes and section.kind.value == "classes" %} {% include "docstring/classes"|get_template with context %} + {% elif config.show_docstring_type_aliases and section.kind.value == "type_aliases" %} + {% include "docstring/type_aliases"|get_template with context %} {% elif config.show_docstring_modules and section.kind.value == "modules" %} {% include "docstring/modules"|get_template with context %} + {% elif config.show_docstring_type_parameters and section.kind.value == "type parameters" %} + {% include "docstring/type_parameters"|get_template with context %} {% elif config.show_docstring_parameters and section.kind.value == "parameters" %} {% include "docstring/parameters"|get_template with context %} {% elif config.show_docstring_other_parameters and section.kind.value == "other parameters" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html new file mode 100644 index 00000000..ae623040 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html @@ -0,0 +1,11 @@ +{% extends "_base/docstring/type_aliases.html.jinja" %} + +{% block logs scoped %} + {{ super() }} + {# TODO: Switch to a warning after some time. #} + {{ log.info( + "DeprecationWarning: Extending '_base/docstring/type_aliases.html' is deprecated, extend '_base/docstring/type_aliases.html.jinja' instead. " ~ + "After some time, this message will be logged as a warning, causing strict builds to fail.", + once=True, + ) }} +{% endblock logs %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html.jinja new file mode 100644 index 00000000..ceaa520c --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html.jinja @@ -0,0 +1,86 @@ +{#- Template for "Type Aliases" sections in docstrings. + +This template renders a list of documented type aliases in the format +specified with the [`docstring_section_style`][] configuration option. + +Context: + section (griffe.DocstringSectionTypeAliases): The section to render. +-#} + +{% block logs scoped %} + {#- Logging block. + + This block can be used to log debug messages, deprecation messages, warnings, etc. + -#} + {{ log.debug("Rendering type aliases section") }} +{% endblock logs %} + +{% import "language"|get_template as lang with context %} +{#- Language module providing the `t` translation method. -#} + +{% if config.docstring_section_style == "table" %} + {% block table_style scoped %} + {#- Block for the `table` section style. -#} +

{{ section.title or lang.t("Type Aliases:") }}

+ + + + + + + + + {% for type_alias in section.value %} + + + + + {% endfor %} + +
{{ lang.t("Name") }}{{ lang.t("Description") }}
{{ type_alias.name }} +
+ {{ type_alias.description|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }} +
+
+ {% endblock table_style %} +{% elif config.docstring_section_style == "list" %} + {% block list_style scoped %} + {#- Block for the `list` section style. -#} +

{{ section.title or lang.t("Type Aliases:") }}

+ + {% endblock list_style %} +{% elif config.docstring_section_style == "spacy" %} + {% block spacy_style scoped %} + {#- Block for the `spacy` section style. -#} + + + + + + + + + {% for type_alias in section.value %} + + + + + {% endfor %} + +
{{ (section.title or lang.t("TYPE ALIAS")).rstrip(":").upper() }}{{ lang.t("DESCRIPTION") }}
{{ type_alias.name }} +
+ {{ type_alias.description|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }} +
+
+ {% endblock spacy_style %} +{% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html new file mode 100644 index 00000000..c08daa1c --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html @@ -0,0 +1,11 @@ +{% extends "_base/docstring/type_parameters.html.jinja" %} + +{% block logs scoped %} + {{ super() }} + {# TODO: Switch to a warning after some time. #} + {{ log.info( + "DeprecationWarning: Extending '_base/docstring/type_parameters.html' is deprecated, extend '_base/docstring/type_parameters.html.jinja' instead. " ~ + "After some time, this message will be logged as a warning, causing strict builds to fail.", + once=True, + ) }} +{% endblock logs %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html.jinja new file mode 100644 index 00000000..5733ba26 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html.jinja @@ -0,0 +1,194 @@ +{#- Template for "Parameters" sections in docstrings. + +This template renders a list of documented type parameters in the format +specified with the [`docstring_section_style`][] configuration option. + +Context: + section (griffe.DocstringSectionTypeParameters): The section to render. +-#} + +{% block logs scoped %} + {#- Logging block. + + This block can be used to log debug messages, deprecation messages, warnings, etc. + -#} + {{ log.debug("Rendering type parameters section") }} +{% endblock logs %} + +{% import "language"|get_template as lang with context %} +{#- Language module providing the `t` translation method. -#} + +{% with %} + {% set is_merged_init = obj.is_function and obj.name == "__init__" and config.merge_init_into_class %} + + {% if config.docstring_section_style == "table" %} + {% block table_style scoped %} + {#- Block for the `table` section style. -#} +

{{ section.title or lang.t("Type Parameters:") if not is_merged_init else lang.t("__init__ Type Parameters:") }}

+ + + + + + + + + + + {% for type_parameter in section.value %} + + + + + + + {% endfor %} + +
{{ lang.t("Name") }}{{ lang.t("Bound or Constraints") }}{{ lang.t("Description") }}{{ lang.t("Default") }}
+ {% if config.type_parameter_headings %} + {% filter heading( + heading_level + 1, + role="typeparam", + id=obj.path ~ ":" ~ type_parameter.name, + class="doc doc-heading doc-heading-type_parameter", + toc_label=(' '|safe if config.show_symbol_type_toc else '') + type_parameter.name, + ) %} + {{ type_parameter.name }} + {% endfilter %} + {% else %} + {{ type_parameter.name }} + {% endif %} + + {% if type_parameter.annotation %} + {% with expression = type_parameter.annotation %} + {% include "expression"|get_template with context %} + {% endwith %} + {% endif %} + +
+ {{ type_parameter.description|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }} +
+
+ {% if type_parameter.default %} + {% with expression = type_parameter.default %} + {% include "expression"|get_template with context %} + {% endwith %} + {% else %} + {{ lang.t("required") }} + {% endif %} +
+ {% endblock table_style %} + {% elif config.docstring_section_style == "list" %} + {% block list_style scoped %} + {#- Block for the `list` section style. -#} +

{{ section.title or lang.t("Type Parameters:") if not is_merged_init else lang.t("__init__ Type Parameters:") }}

+ + {% endblock list_style %} + {% elif config.docstring_section_style == "spacy" %} + {% block spacy_style scoped %} + {#- Block for the `spacy` section style. -#} + + + + + + + + + {% for type_parameter in section.value %} + + + + + {% endfor %} + +
{{ (section.title or lang.t("TYPE PARAMETER")).rstrip(":").upper() if not is_merged_init else lang.t("__init__ TYPE PARAMETER") }}{{ lang.t("DESCRIPTION") }}
+ {% if config.type_parameter_headings %} + {% filter heading( + heading_level + 1, + role="typeparam", + id=obj.path ~ ":" ~ type_parameter.name , + class="doc doc-heading doc-heading-type_parameter", + toc_label=(' '|safe if config.show_symbol_type_toc else '') + type_parameter.name, + ) %} + {{ type_parameter.name }} + {% endfilter %} + {% else %} + {{ type_parameter.name }} + {% endif %} + +
+ {{ type_parameter.description|convert_markdown(heading_level, html_id, autoref_hook=autoref_hook) }} +
+

+ {% if type_parameter.constraints %} + + {{ lang.t("CONSTRAINTS:") }} + {% for constraint in type_parameter.constraints -%} + {%- with expression = constraint -%} + {% include "expression"|get_template with context %} + {%- endwith -%} + {%- if not loop.last %}, {% endif -%} + {% endfor %} + + {% elif type_parameter.bound %} + + {{ lang.t("BOUND:") }} + {% with expression = type_parameter.bound %} + {% include "expression"|get_template with context %} + {% endwith %} + + {% endif %} + {% if type_parameter.default %} + + {{ lang.t("DEFAULT:") }} + {% with expression = type_parameter.default %} + {% include "expression"|get_template with context %} + {% endwith %} + + {% endif %} +

+
+ {% endblock spacy_style %} + {% endif %} +{% endwith %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja index 4aea143d..a4aae673 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja @@ -2,18 +2,41 @@ This template renders a Griffe expression, which is a tree-like structure representing a Python expression. + +Context: + expression (griffe.Expr): The expression to render. + config (dict): The configuration options. -#} {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {% endblock logs %} {%- macro crossref(name, annotation_path) -%} {#- Output a cross-reference. - + + This macro outputs a cross-reference to the given name. + + Parameters: + name (griffe.ExprName): The name to cross-reference. + annotation_path (str): Either "brief", "source", or "full". + + Returns: + Either a cross-reference (using an autoref element) or the name itself. + -#} + {%- if name.classname == "ExprName" and name.is_type_parameter -%} + {{ type_param_crossref(name) }} + {%- else -%} + {{ object_crossref(name, annotation_path) }} + {%- endif -%} +{%- endmacro -%} + +{%- macro object_crossref(name, annotation_path) -%} + {#- Output a cross-reference to a Griffe object. + This macro outputs a cross-reference to the given name. Parameters: @@ -49,6 +72,26 @@ which is a tree-like structure representing a Python expression. {%- endwith -%} {%- endmacro -%} +{%- macro type_param_crossref(name) -%} + {#- Render a cross-reference to a type parameter heading. + + Parameters: + name (griffe.ExprName): The name to cross-reference. + + Returns: + The autorefs cross-reference, or the type parameter name. + -#} + {%- if not signature -%} + {{ name.name }} + {%- elif config.signature_crossrefs -%} + {%- filter stash_crossref(length=name.name|length) -%} + {{ name.name }} + {%- endfilter -%} + {%- else -%} + {{ name.name }} + {%- endif -%} +{%- endmacro -%} + {%- macro param_crossref(expression) -%} {#- Render a cross-reference to a parameter heading. @@ -88,7 +131,14 @@ which is a tree-like structure representing a Python expression. {%- elif config.unwrap_annotated and expression.classname == "ExprSubscript" and expression.canonical_path in ("typing.Annotated", "typing_extensions.Annotated") -%} {{ render(expression.slice.elements[0], annotations_path) }} {%- elif expression.classname == "ExprAttribute" -%} - {%- if annotations_path == "brief" -%} + {%- if expression.first.is_type_parameter -%} + {{ type_param_crossref(expression.first) }} + {%- for element in expression -%} + {%- if not loop.first -%} + {{ render(element, "brief") }} + {%- endif -%} + {%- endfor -%} + {%- elif annotations_path == "brief" -%} {%- if expression.last.is_enum_value -%} {{ crossref(expression.last.parent, "brief") }}.value {%- else -%} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja index d988b6ab..6186d9f7 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja @@ -2,7 +2,7 @@ {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {% endblock logs %} @@ -10,8 +10,11 @@ {% macro t(key) %}{{ { "ATTRIBUTE": "ATTRIBUTE", "Attributes:": "Attributes:", + "BOUND:": "BOUND:", + "Bound or Constraints": "Bound or Constraints", "Classes:": "Classes:", "CLASS": "CLASS", + "CONSTRAINTS:": "CONSTRAINTS:", "DEFAULT:": "DEFAULT:", "Default": "Default", "default:": "default:", @@ -38,6 +41,12 @@ "Source code in": "Source code in", "TYPE:": "TYPE:", "Type": "Type", + "Type Aliases:": "Type Aliases:", + "TYPE ALIAS": "TYPE ALIAS", + "Type Parameters:": "Type Parameters:", + "__init__ Type Parameters:": "__init__ Type Parameters:"|safe, + "TYPE PARAMETER": "TYPE PARAMETER", + "__init__ TYPE PARAMETER": "__init__ TYPE PARAMETER"|safe, "WARNS": "WARNS", "Warns:": "Warns:", "YIELDS": "YIELDS", diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja index 508e5660..f1e110a8 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja +++ b/src/mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja @@ -2,7 +2,7 @@ {% block logs scoped %} {#- Logging block. - + This block can be used to log debug messages, deprecation messages, warnings, etc. -#} {% endblock logs %} @@ -12,6 +12,10 @@ {% include "summary/modules"|get_template with context %} {% endif %} + {% if config.summary.type_aliases %} + {% include "summary/type_aliases"|get_template with context %} + {% endif %} + {% if config.summary.classes %} {% include "summary/classes"|get_template with context %} {% endif %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html b/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html new file mode 100644 index 00000000..bf0e6ca0 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html @@ -0,0 +1,11 @@ +{% extends "_base/summary/type_aliases.html.jinja" %} + +{% block logs scoped %} + {{ super() }} + {# TODO: Switch to a warning after some time. #} + {{ log.info( + "DeprecationWarning: Extending '_base/type_aliases/classes.html' is deprecated, extend '_base/type_aliases/classes.html.jinja' instead. " ~ + "After some time, this message will be logged as a warning, causing strict builds to fail.", + once=True, + ) }} +{% endblock logs %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html.jinja new file mode 100644 index 00000000..ce62269c --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html.jinja @@ -0,0 +1,21 @@ +{#- Summary of type aliases. -#} + +{% block logs scoped %} + {#- Logging block. + + This block can be used to log debug messages, deprecation messages, warnings, etc. + -#} +{% endblock logs %} + +{% with section = obj.type_aliases + |filter_objects( + filters=config.filters, + members_list=members_list, + inherited_members=config.inherited_members, + keep_no_docstrings=config.show_if_no_docstring, + ) + |order_members(config.members_order, members_list) + |as_type_aliases_section(check_public=not members_list) + %} + {% if section %}{% include "docstring/type_aliases"|get_template with context %}{% endif %} +{% endwith %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html b/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html new file mode 100644 index 00000000..18b50751 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html @@ -0,0 +1,11 @@ +{% extends "_base/type_alias.html.jinja" %} + +{% block logs scoped %} + {{ super() }} + {# TODO: Switch to a warning after some time. #} + {{ log.info( + "DeprecationWarning: Extending '_base/type_alias.html' is deprecated, extend '_base/type_alias.html.jinja' instead. " ~ + "After some time, this message will be logged as a warning, causing strict builds to fail.", + once=True, + ) }} +{% endblock logs %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html.jinja new file mode 100644 index 00000000..5a21f8a6 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/type_alias.html.jinja @@ -0,0 +1,117 @@ +{#- Template for Python type aliases. + +This template renders a Python type alias. + +Context: + type_alias (griffe.TypeAlias): The type alias to render. + root (bool): Whether this is the root object, injected with `:::` in a Markdown page. + heading_level (int): The HTML heading level to use. + config (dict): The configuration options. +-#} + +{% block logs scoped %} + {#- Logging block. + + This block can be used to log debug messages, deprecation messages, warnings, etc. + -#} + {{ log.debug("Rendering " + type_alias.path) }} +{% endblock logs %} + +
+ {% with obj = type_alias, html_id = type_alias.path %} + + {% if root %} + {% set show_full_path = config.show_root_full_path %} + {% set root_members = True %} + {% elif root_members %} + {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %} + {% set root_members = False %} + {% else %} + {% set show_full_path = config.show_object_full_path %} + {% endif %} + + {% set type_alias_name = type_alias.path if show_full_path else type_alias.name %} + + {% if not root or config.show_root_heading %} + {% filter heading( + heading_level, + role="typealias", + id=html_id, + class="doc doc-heading", + toc_label=(' '|safe if config.show_symbol_type_toc else '') + type_alias.name, + ) %} + + {% block heading scoped %} + {#- Heading block. + + This block renders the heading for the type alias. + -#} + {% if config.show_symbol_type_heading %}{% endif %} + {% if config.separate_signature %} + {{ type_alias_name }} + {% else %} + {%+ filter highlight(language="python", inline=True) %} + {{ type_alias_name }}{% include "type_parameters"|get_template with context %} = {{ type_alias.value }} + {% endfilter %} + {% endif %} + {% endblock heading %} + + {% block labels scoped %} + {#- Labels block. + + This block renders the labels for the type alias. + -#} + {% with labels = type_alias.labels %} + {% include "labels"|get_template with context %} + {% endwith %} + {% endblock labels %} + + {% endfilter %} + + {% block signature scoped %} + {#- Signature block. + + This block renders the signature for the type alias. + -#} + {% if config.separate_signature %} + {% filter format_type_alias(type_alias, config.line_length, crossrefs=config.signature_crossrefs) %} + {{ type_alias.name }} + {% endfilter %} + {% endif %} + {% endblock signature %} + + {% else %} + {% if config.show_root_toc_entry %} + {% filter heading(heading_level, + role="typealias", + id=html_id, + toc_label=(' '|safe if config.show_symbol_type_toc else '') + type_alias.name, + hidden=True, + ) %} + {% endfilter %} + {% endif %} + {% set heading_level = heading_level - 1 %} + {% endif %} + +
+ {% block contents scoped %} + {#- Contents block. + + This block renders the contents of the type alias. + It contains other blocks that users can override. + Overriding the contents block allows to rearrange the order of the blocks. + -#} + {% block docstring scoped %} + {#- Docstring block. + + This block renders the docstring for the type alias. + -#} + {% with docstring_sections = type_alias.docstring.parsed %} + {% include "docstring"|get_template with context %} + {% endwith %} + {% endblock docstring %} + {% endblock contents %} +
+ + {% endwith %} +
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html b/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html new file mode 100644 index 00000000..7ab61d17 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html @@ -0,0 +1,11 @@ +{% extends "_base/type_parameters.html.jinja" %} + +{% block logs scoped %} + {{ super() }} + {# TODO: Switch to a warning after some time. #} + {{ log.info( + "DeprecationWarning: Extending '_base/type_parameters.html' is deprecated, extend '_base/type_parameters.html.jinja' instead. " ~ + "After some time, this message will be logged as a warning, causing strict builds to fail.", + once=True, + ) }} +{% endblock logs %} diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html.jinja b/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html.jinja new file mode 100644 index 00000000..5303c161 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/_base/type_parameters.html.jinja @@ -0,0 +1,93 @@ +{#- Template for type parameters. + +This template renders the type parameters of a generic obj. +It iterates over the type parameters of the object to rebuild the signature. +The signature is the list of type parameters of a generic object, including their names, default values, and bound or constraints. + +Context: + obj (griffe.Object): The object to render. + config (dict): The configuration options. +-#} + +{%- if config.show_signature_type_parameters -%} + {%- block logs scoped -%} + {#- Logging block. + + This block can be used to log debug messages, deprecation messages, warnings, etc. + -#} + {{ log.debug("Rendering type parameters") }} + {%- endblock logs -%} + {%- with -%} + + {%- set ns = namespace( + annotation="", + equal="=", + default=False, + ) -%} + + {%- if obj.is_generic -%} + [ + {%- for type_parameter in obj.type_parameters -%} + {#- Prepare type bound or constraints. -#} + {%- if config.show_signature_annotations and type_parameter.annotation is not none -%} + {%- set ns.equal = " = " -%} + {%- if config.separate_signature and config.signature_crossrefs -%} + {%- with expression = type_parameter.annotation -%} + {%- set ns.annotation -%}: {% include "expression"|get_template with context %}{%- endset -%} + {%- endwith -%} + {%- else -%} + {%- set ns.annotation = ": " + type_parameter.annotation|safe -%} + {%- endif -%} + {%- else -%} + {%- set ns.equal = "=" -%} + {%- set ns.annotation = "" -%} + {%- endif -%} + + {#- Prepare default value. -#} + {%- if type_parameter.default is not none -%} + {%- set ns.default = True -%} + {%- else -%} + {%- set ns.default = False -%} + {%- endif -%} + + {#- Prepare name. -#} + {%- set type_param_prefix -%} + {%- if type_parameter.kind == "type-var-tuple" -%} + * + {%- elif type_parameter.kind == "param-spec" -%} + ** + {%- endif -%} + {%- endset -%} + + {#- Render type parameter name with optional cross-reference to its heading. -#} + {{ type_param_prefix }} + {%- if config.separate_signature and config.type_parameter_headings and config.signature_crossrefs -%} + {%- filter stash_crossref(length=type_parameter.name|length) -%} + {{ type_parameter.name }} + {%- endfilter -%} + {%- else -%} + {{ type_parameter.name }} + {%- endif -%} + + {#- Render type parameter bound or constraints. -#} + {{ ns.annotation }} + + {#- Render type parameter default value. -#} + {%- if ns.default -%} + {{ ns.equal }} + {%- if config.signature_crossrefs and config.separate_signature -%} + {%- with expression = type_parameter.default -%} + {%- include "expression"|get_template with context -%} + {%- endwith -%} + {%- else -%} + {{ type_parameter.default|safe }} + {%- endif -%} + {%- endif -%} + + {%- if not loop.last %}, {% endif -%} + {%- endfor -%} + ] + {%- endif -%} + + {%- endwith -%} +{%- endif -%} diff --git a/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html b/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html new file mode 100644 index 00000000..78bd497a --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html @@ -0,0 +1 @@ +{% extends "_base/docstring/type_aliases.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html.jinja b/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html.jinja new file mode 100644 index 00000000..78bd497a --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html.jinja @@ -0,0 +1 @@ +{% extends "_base/docstring/type_aliases.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html b/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html new file mode 100644 index 00000000..223fbb04 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html @@ -0,0 +1 @@ +{% extends "_base/docstring/type_parameters.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html.jinja b/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html.jinja new file mode 100644 index 00000000..223fbb04 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html.jinja @@ -0,0 +1 @@ +{% extends "_base/docstring/type_parameters.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/style.css b/src/mkdocstrings_handlers/python/templates/material/style.css index 7e819d8b..ae89d782 100644 --- a/src/mkdocstrings_handlers/python/templates/material/style.css +++ b/src/mkdocstrings_handlers/python/templates/material/style.css @@ -21,17 +21,20 @@ } /* Defaults in Spacy table style. */ -.doc-param-default { +.doc-param-default, +.doc-type_param-default { float: right; } /* Parameter headings must be inline, not blocks. */ -.doc-heading-parameter { +.doc-heading-parameter, +.doc-heading-type_parameter { display: inline; } /* Prefer space on the right, not the left of parameter permalinks. */ -.doc-heading-parameter .headerlink { +.doc-heading-parameter .headerlink, +.doc-heading-type_parameter .headerlink { margin-left: 0 !important; margin-right: 0.2rem; } @@ -45,33 +48,41 @@ :root, :host, [data-md-color-scheme="default"] { --doc-symbol-parameter-fg-color: #df50af; + --doc-symbol-type_parameter-fg-color: #df50af; --doc-symbol-attribute-fg-color: #953800; --doc-symbol-function-fg-color: #8250df; --doc-symbol-method-fg-color: #8250df; --doc-symbol-class-fg-color: #0550ae; + --doc-symbol-type_alias-fg-color: #0550ae; --doc-symbol-module-fg-color: #5cad0f; --doc-symbol-parameter-bg-color: #df50af1a; + --doc-symbol-type_parameter-bg-color: #df50af1a; --doc-symbol-attribute-bg-color: #9538001a; --doc-symbol-function-bg-color: #8250df1a; --doc-symbol-method-bg-color: #8250df1a; --doc-symbol-class-bg-color: #0550ae1a; + --doc-symbol-type_alias-bg-color: #0550ae1a; --doc-symbol-module-bg-color: #5cad0f1a; } [data-md-color-scheme="slate"] { --doc-symbol-parameter-fg-color: #ffa8cc; + --doc-symbol-type_parameter-fg-color: #ffa8cc; --doc-symbol-attribute-fg-color: #ffa657; --doc-symbol-function-fg-color: #d2a8ff; --doc-symbol-method-fg-color: #d2a8ff; --doc-symbol-class-fg-color: #79c0ff; + --doc-symbol-type_alias-fg-color: #79c0ff; --doc-symbol-module-fg-color: #baff79; --doc-symbol-parameter-bg-color: #ffa8cc1a; + --doc-symbol-type_parameter-bg-color: #ffa8cc1a; --doc-symbol-attribute-bg-color: #ffa6571a; --doc-symbol-function-bg-color: #d2a8ff1a; --doc-symbol-method-bg-color: #d2a8ff1a; --doc-symbol-class-bg-color: #79c0ff1a; + --doc-symbol-type_alias-bg-color: #79c0ff1a; --doc-symbol-module-bg-color: #baff791a; } @@ -91,6 +102,15 @@ code.doc-symbol-parameter::after { content: "param"; } +code.doc-symbol-type_parameter { + color: var(--doc-symbol-type_parameter-fg-color); + background-color: var(--doc-symbol-type_parameter-bg-color); +} + +code.doc-symbol-type_parameter::after { + content: "type-param"; +} + code.doc-symbol-attribute { color: var(--doc-symbol-attribute-fg-color); background-color: var(--doc-symbol-attribute-bg-color); @@ -127,6 +147,15 @@ code.doc-symbol-class::after { content: "class"; } +code.doc-symbol-type_alias { + color: var(--doc-symbol-type_alias-fg-color); + background-color: var(--doc-symbol-type_alias-bg-color); +} + +code.doc-symbol-type_alias::after { + content: "alias"; +} + code.doc-symbol-module { color: var(--doc-symbol-module-fg-color); background-color: var(--doc-symbol-module-bg-color); diff --git a/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html b/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html new file mode 100644 index 00000000..ca10bc88 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html @@ -0,0 +1 @@ +{% extends "_base/summary/type_aliases.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html.jinja b/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html.jinja new file mode 100644 index 00000000..ca10bc88 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/summary/type_aliases.html.jinja @@ -0,0 +1 @@ +{% extends "_base/summary/type_aliases.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/type_alias.html b/src/mkdocstrings_handlers/python/templates/material/type_alias.html new file mode 100644 index 00000000..5139a2db --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/type_alias.html @@ -0,0 +1 @@ +{% extends "_base/type_alias.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/type_alias.html.jinja b/src/mkdocstrings_handlers/python/templates/material/type_alias.html.jinja new file mode 100644 index 00000000..5139a2db --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/type_alias.html.jinja @@ -0,0 +1 @@ +{% extends "_base/type_alias.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/type_parameters.html b/src/mkdocstrings_handlers/python/templates/material/type_parameters.html new file mode 100644 index 00000000..c39ca528 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/type_parameters.html @@ -0,0 +1 @@ +{% extends "_base/type_parameters.html.jinja" %} diff --git a/src/mkdocstrings_handlers/python/templates/material/type_parameters.html.jinja b/src/mkdocstrings_handlers/python/templates/material/type_parameters.html.jinja new file mode 100644 index 00000000..c39ca528 --- /dev/null +++ b/src/mkdocstrings_handlers/python/templates/material/type_parameters.html.jinja @@ -0,0 +1 @@ +{% extends "_base/type_parameters.html.jinja" %} diff --git a/tests/snapshots/__init__.py b/tests/snapshots/__init__.py index 4469afed..f9c00d43 100644 --- a/tests/snapshots/__init__.py +++ b/tests/snapshots/__init__.py @@ -18,17 +18,17 @@ ("separate_signature", False), ("show_signature_annotations", True), ("signature_crossrefs", True), - ): external("735fc6ffdb82*.html"), + ): external("59872531a086*.html"), ( ("separate_signature", False), ("show_signature_annotations", False), ("signature_crossrefs", True), - ): external("6a02b544c12c*.html"), + ): external("1c04883284f6*.html"), ( ("separate_signature", False), ("show_signature_annotations", False), ("signature_crossrefs", False), - ): external("b060b701543e*.html"), + ): external("b0761b5d88e0*.html"), ( ("separate_signature", True), ("show_signature_annotations", True), @@ -43,7 +43,7 @@ ("separate_signature", False), ("show_signature_annotations", True), ("signature_crossrefs", False), - ): external("d1216ebf8e30*.html"), + ): external("9c7eeb0d7bfb*.html"), }, ) @@ -55,10 +55,10 @@ ("members", False), ): external("ab0ddac637b5*.html"), (("filters", None), ("inherited_members", True), ("members", True)): external( - "0b1372d7f7c0*.html", + "5206643f1d79*.html", ), (("filters", ()), ("inherited_members", False), ("members", True)): external( - "59a9e1ffb2f0*.html", + "2688494d14e8*.html", ), ( ("filters", ("!module_attribute",)), @@ -74,7 +74,7 @@ ("members", ("module_attribute",)), ): external("e90c3e0c85dd*.html"), (("filters", ()), ("inherited_members", True), ("members", True)): external( - "e8be7a9b1410*.html", + "bf3b380c0319*.html", ), ( ("filters", ("module_attribute",)), @@ -85,7 +85,7 @@ ("filters", ()), ("inherited_members", ("method1",)), ("members", True), - ): external("d540895f6bf9*.html"), + ): external("0e5bca1984e9*.html"), (("filters", ()), ("inherited_members", False), ("members", False)): external( "5cf0130e3b4f*.html", ), @@ -93,7 +93,7 @@ ("filters", ("!module_attribute",)), ("inherited_members", True), ("members", True), - ): external("7c988c9e13ef*.html"), + ): external("dc101bbf9385*.html"), ( ("filters", ("!module_attribute",)), ("inherited_members", False), @@ -128,7 +128,7 @@ ("members", None), ): external("cfcd41685591*.html"), (("filters", ()), ("inherited_members", False), ("members", None)): external( - "a2c5be9bd5d1*.html", + "ca8e03e3261a*.html", ), ( ("filters", ("module_attribute",)), @@ -157,7 +157,7 @@ ("filters", ("!module_attribute",)), ("inherited_members", ("method1",)), ("members", None), - ): external("3d072a22b951*.html"), + ): external("3313930abb15*.html"), (("filters", None), ("inherited_members", False), ("members", False)): external( "9bd282a6f2fe*.html", ), @@ -170,7 +170,7 @@ "44e42f27bfe3*.html", ), (("filters", None), ("inherited_members", False), ("members", None)): external( - "f7711b8af768*.html", + "2e4d65061027*.html", ), ( ("filters", ("!module_attribute",)), @@ -183,13 +183,13 @@ ("members", False), ): external("f3f3acb6b51b*.html"), (("filters", None), ("inherited_members", ()), ("members", True)): external( - "347d4ffe2cb3*.html", + "4312e98ede3c*.html", ), ( ("filters", ("!module_attribute",)), ("inherited_members", True), ("members", None), - ): external("ba51e100acd4*.html"), + ): external("8306095b18c4*.html"), ( ("filters", ("!module_attribute",)), ("inherited_members", False), @@ -216,10 +216,10 @@ ("members", ()), ): external("d5a6bf59c663*.html"), (("filters", None), ("inherited_members", ()), ("members", None)): external( - "88855b028417*.html", + "06b3a345d3df*.html", ), (("filters", ()), ("inherited_members", True), ("members", None)): external( - "981438492e38*.html", + "e555bf966edd*.html", ), ( ("filters", ()), @@ -230,25 +230,25 @@ ("filters", None), ("inherited_members", ("method1",)), ("members", None), - ): external("ae74b5980f9b*.html"), + ): external("adcc51aa0d87*.html"), ( ("filters", ("module_attribute",)), ("inherited_members", True), ("members", ()), ): external("95f8e480937f*.html"), (("filters", None), ("inherited_members", False), ("members", True)): external( - "831198033381*.html", + "e22a35456321*.html", ), ( ("filters", ("module_attribute",)), ("inherited_members", True), ("members", True), - ): external("052c34f22e4c*.html"), + ): external("d7988a46775a*.html"), ( ("filters", ("!module_attribute",)), ("inherited_members", False), ("members", None), - ): external("cdc8126d78b6*.html"), + ): external("94faed07f275*.html"), ( ("filters", ("module_attribute",)), ("inherited_members", ("method1",)), @@ -271,7 +271,7 @@ ("filters", None), ("inherited_members", ("method1",)), ("members", True), - ): external("7d5fe6653919*.html"), + ): external("f697469880cb*.html"), ( ("filters", ("!module_attribute",)), ("inherited_members", True), @@ -294,7 +294,7 @@ ("filters", ("module_attribute",)), ("inherited_members", ()), ("members", True), - ): external("46e56f39b10d*.html"), + ): external("c90af3fe1d72*.html"), ( ("filters", ()), ("inherited_members", ()), @@ -317,7 +317,7 @@ ("filters", ("module_attribute",)), ("inherited_members", False), ("members", True), - ): external("052e71e7e9d5*.html"), + ): external("059dc5c474ca*.html"), ( ("filters", None), ("inherited_members", ("method1",)), @@ -327,7 +327,7 @@ ("filters", ("!module_attribute",)), ("inherited_members", ()), ("members", True), - ): external("b4b490164ab1*.html"), + ): external("3ea5302e71e5*.html"), ( ("filters", ("!module_attribute",)), ("inherited_members", ("method1",)), @@ -342,7 +342,7 @@ ("filters", ("!module_attribute",)), ("inherited_members", ()), ("members", None), - ): external("728c13446301*.html"), + ): external("adcecdb71c09*.html"), (("filters", None), ("inherited_members", ()), ("members", ())): external( "f77f1c850398*.html", ), @@ -350,12 +350,12 @@ ("filters", ("!module_attribute",)), ("inherited_members", False), ("members", True), - ): external("0fac4f5e7f45*.html"), + ): external("5e331d13e0e0*.html"), (("filters", None), ("inherited_members", True), ("members", None)): external( - "cc19537fdba4*.html", + "1895a0c88668*.html", ), (("filters", ()), ("inherited_members", ()), ("members", None)): external( - "e6a9b76f268c*.html", + "76176ed54147*.html", ), ( ("filters", ("!module_attribute",)), @@ -366,7 +366,7 @@ ("filters", ("!module_attribute",)), ("inherited_members", ("method1",)), ("members", True), - ): external("0c2924ff976f*.html"), + ): external("14c3d2f7287b*.html"), ( ("filters", ("module_attribute",)), ("inherited_members", ()), @@ -376,7 +376,7 @@ "b0a9b08f1f72*.html", ), (("filters", ()), ("inherited_members", ()), ("members", True)): external( - "fb65efbbfc3e*.html", + "7f570c4de561*.html", ), ( ("filters", ("module_attribute",)), @@ -390,12 +390,12 @@ ("filters", ("module_attribute",)), ("inherited_members", ("method1",)), ("members", True), - ): external("a1167b14f5a7*.html"), + ): external("fa334e855708*.html"), ( ("filters", ()), ("inherited_members", ("method1",)), ("members", None), - ): external("f848d4a9e516*.html"), + ): external("57e7bb4ad48c*.html"), ( ("filters", ("module_attribute",)), ("inherited_members", ()), diff --git a/tests/snapshots/external/052e71e7e9d5bec710fb2d36b009122c48eca0a19d0611df530e607f5bacdf6f.html b/tests/snapshots/external/059dc5c474ca9f18b173398bbd93fbda465cdfd2189cb2e9ef37a3d46cccc337.html similarity index 92% rename from tests/snapshots/external/052e71e7e9d5bec710fb2d36b009122c48eca0a19d0611df530e607f5bacdf6f.html rename to tests/snapshots/external/059dc5c474ca9f18b173398bbd93fbda465cdfd2189cb2e9ef37a3d46cccc337.html index 6866b45f..4d39cd4b 100644 --- a/tests/snapshots/external/052e71e7e9d5bec710fb2d36b009122c48eca0a19d0611df530e607f5bacdf6f.html +++ b/tests/snapshots/external/059dc5c474ca9f18b173398bbd93fbda465cdfd2189cb2e9ef37a3d46cccc337.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -70,8 +72,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/88855b0284174733b57edd2043e0e8cd6a1a0223055f08b80031452eb05d9484.html b/tests/snapshots/external/06b3a345d3df34cdb016206e9f4dce76c6ef07342d5a0b1a6f53d2db6372a110.html similarity index 95% rename from tests/snapshots/external/88855b0284174733b57edd2043e0e8cd6a1a0223055f08b80031452eb05d9484.html rename to tests/snapshots/external/06b3a345d3df34cdb016206e9f4dce76c6ef07342d5a0b1a6f53d2db6372a110.html index 540a2f6a..4040581a 100644 --- a/tests/snapshots/external/88855b0284174733b57edd2043e0e8cd6a1a0223055f08b80031452eb05d9484.html +++ b/tests/snapshots/external/06b3a345d3df34cdb016206e9f4dce76c6ef07342d5a0b1a6f53d2db6372a110.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/d540895f6bf91c8c8e4abc02f40529a61c6cec71b18da2e4f02206ec18b901ef.html b/tests/snapshots/external/0e5bca1984e9323ddda836bff6fd828d82f5c333a319b533d3e3785535a8b670.html similarity index 96% rename from tests/snapshots/external/d540895f6bf91c8c8e4abc02f40529a61c6cec71b18da2e4f02206ec18b901ef.html rename to tests/snapshots/external/0e5bca1984e9323ddda836bff6fd828d82f5c333a319b533d3e3785535a8b670.html index 2ad1c277..1872aec2 100644 --- a/tests/snapshots/external/d540895f6bf91c8c8e4abc02f40529a61c6cec71b18da2e4f02206ec18b901ef.html +++ b/tests/snapshots/external/0e5bca1984e9323ddda836bff6fd828d82f5c333a319b533d3e3785535a8b670.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/0c2924ff976fa0e32ba66558a4f9e1eff4cd66196506a37977cdb33325a50718.html b/tests/snapshots/external/14c3d2f7287bed04cc17f33b229b436021b1bba526e5049798da2a45d7ff5773.html similarity index 96% rename from tests/snapshots/external/0c2924ff976fa0e32ba66558a4f9e1eff4cd66196506a37977cdb33325a50718.html rename to tests/snapshots/external/14c3d2f7287bed04cc17f33b229b436021b1bba526e5049798da2a45d7ff5773.html index 5fb3da58..23b4db17 100644 --- a/tests/snapshots/external/0c2924ff976fa0e32ba66558a4f9e1eff4cd66196506a37977cdb33325a50718.html +++ b/tests/snapshots/external/14c3d2f7287bed04cc17f33b229b436021b1bba526e5049798da2a45d7ff5773.html @@ -54,8 +54,10 @@

- - Class + + + Class +

@@ -142,8 +144,10 @@

- - NestedClass + + + NestedClass +

@@ -260,8 +264,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/cc19537fdba4a26b10c60d5586b0eb7ef0264a783a3c47d1114d21fa8cfa3947.html b/tests/snapshots/external/1895a0c8866802749b131163be9b937e293cd71f784d87e11ef0c9fdaf606c35.html similarity index 96% rename from tests/snapshots/external/cc19537fdba4a26b10c60d5586b0eb7ef0264a783a3c47d1114d21fa8cfa3947.html rename to tests/snapshots/external/1895a0c8866802749b131163be9b937e293cd71f784d87e11ef0c9fdaf606c35.html index f93ae024..4c08b11a 100644 --- a/tests/snapshots/external/cc19537fdba4a26b10c60d5586b0eb7ef0264a783a3c47d1114d21fa8cfa3947.html +++ b/tests/snapshots/external/1895a0c8866802749b131163be9b937e293cd71f784d87e11ef0c9fdaf606c35.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

@@ -352,8 +358,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/6a02b544c12c68b75d9bf3b85b1800830fd980daabff9df8c3760eb6edea7915.html b/tests/snapshots/external/1c04883284f64469144c1a2b36edb741c727581a566cb55e2c07e0aaa231ec5c.html similarity index 96% rename from tests/snapshots/external/6a02b544c12c68b75d9bf3b85b1800830fd980daabff9df8c3760eb6edea7915.html rename to tests/snapshots/external/1c04883284f64469144c1a2b36edb741c727581a566cb55e2c07e0aaa231ec5c.html index 70567c97..2a424f53 100644 --- a/tests/snapshots/external/6a02b544c12c68b75d9bf3b85b1800830fd980daabff9df8c3760eb6edea7915.html +++ b/tests/snapshots/external/1c04883284f64469144c1a2b36edb741c727581a566cb55e2c07e0aaa231ec5c.html @@ -16,8 +16,10 @@

- - Class + + + Class +

diff --git a/tests/snapshots/external/59a9e1ffb2f0807b594a933444c78753a06f359527ea4adac85c72a7812b21d3.html b/tests/snapshots/external/2688494d14e8513049d7ed6e29f38f9392dfb724dedaf4b3a40b922a07f5b481.html similarity index 95% rename from tests/snapshots/external/59a9e1ffb2f0807b594a933444c78753a06f359527ea4adac85c72a7812b21d3.html rename to tests/snapshots/external/2688494d14e8513049d7ed6e29f38f9392dfb724dedaf4b3a40b922a07f5b481.html index ad60041c..81142770 100644 --- a/tests/snapshots/external/59a9e1ffb2f0807b594a933444c78753a06f359527ea4adac85c72a7812b21d3.html +++ b/tests/snapshots/external/2688494d14e8513049d7ed6e29f38f9392dfb724dedaf4b3a40b922a07f5b481.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/f7711b8af7689b331209f8c034c8cc3a2ec894372644a8eaee597418e9b55b3c.html b/tests/snapshots/external/2e4d6506102788db04c9c337cecd1a70fad7aa6a643c91a9d9c92c2b6190eba3.html similarity index 95% rename from tests/snapshots/external/f7711b8af7689b331209f8c034c8cc3a2ec894372644a8eaee597418e9b55b3c.html rename to tests/snapshots/external/2e4d6506102788db04c9c337cecd1a70fad7aa6a643c91a9d9c92c2b6190eba3.html index 522fd1c1..cb7e1f8d 100644 --- a/tests/snapshots/external/f7711b8af7689b331209f8c034c8cc3a2ec894372644a8eaee597418e9b55b3c.html +++ b/tests/snapshots/external/2e4d6506102788db04c9c337cecd1a70fad7aa6a643c91a9d9c92c2b6190eba3.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/3d072a22b9513eecb51c6a5f39b978c1c1d3ef56a572031a307fe1cad1f17eff.html b/tests/snapshots/external/3313930abb1518b3b19a98860f58d43272546702918d07e1f59e8a1f093659c8.html similarity index 95% rename from tests/snapshots/external/3d072a22b9513eecb51c6a5f39b978c1c1d3ef56a572031a307fe1cad1f17eff.html rename to tests/snapshots/external/3313930abb1518b3b19a98860f58d43272546702918d07e1f59e8a1f093659c8.html index f950f69b..adea652e 100644 --- a/tests/snapshots/external/3d072a22b9513eecb51c6a5f39b978c1c1d3ef56a572031a307fe1cad1f17eff.html +++ b/tests/snapshots/external/3313930abb1518b3b19a98860f58d43272546702918d07e1f59e8a1f093659c8.html @@ -23,8 +23,10 @@

- - Class + + + Class +

@@ -111,8 +113,10 @@

- - NestedClass + + + NestedClass +

@@ -229,8 +233,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/b4b490164ab1a724cac7aba25bbc69a33e7dd44500e9337718cd96da1bb56325.html b/tests/snapshots/external/3ea5302e71e5f159fe65675ab65f15771db1cd5da7b2339fbc79d2d301a284e5.html similarity index 95% rename from tests/snapshots/external/b4b490164ab1a724cac7aba25bbc69a33e7dd44500e9337718cd96da1bb56325.html rename to tests/snapshots/external/3ea5302e71e5f159fe65675ab65f15771db1cd5da7b2339fbc79d2d301a284e5.html index 9f5cbef9..343045ea 100644 --- a/tests/snapshots/external/b4b490164ab1a724cac7aba25bbc69a33e7dd44500e9337718cd96da1bb56325.html +++ b/tests/snapshots/external/3ea5302e71e5f159fe65675ab65f15771db1cd5da7b2339fbc79d2d301a284e5.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/347d4ffe2cb3f2ca3f0d1f3f09cffa96645eb2af29983e75d807fccff96d8f75.html b/tests/snapshots/external/4312e98ede3cbcc1eb405bf086b518d4783f1eef142d6110dbca727fdf05ba2a.html similarity index 95% rename from tests/snapshots/external/347d4ffe2cb3f2ca3f0d1f3f09cffa96645eb2af29983e75d807fccff96d8f75.html rename to tests/snapshots/external/4312e98ede3cbcc1eb405bf086b518d4783f1eef142d6110dbca727fdf05ba2a.html index 9cd4b2fe..cd44a0d6 100644 --- a/tests/snapshots/external/347d4ffe2cb3f2ca3f0d1f3f09cffa96645eb2af29983e75d807fccff96d8f75.html +++ b/tests/snapshots/external/4312e98ede3cbcc1eb405bf086b518d4783f1eef142d6110dbca727fdf05ba2a.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/0b1372d7f7c057905f665ad506f3dd3bee62fb9b1c8b2a39991550e7845c2b02.html b/tests/snapshots/external/5206643f1d7951daaeaddc1b7dece75a61dda67ec3cb7cf98b84cbb3383a4544.html similarity index 96% rename from tests/snapshots/external/0b1372d7f7c057905f665ad506f3dd3bee62fb9b1c8b2a39991550e7845c2b02.html rename to tests/snapshots/external/5206643f1d7951daaeaddc1b7dece75a61dda67ec3cb7cf98b84cbb3383a4544.html index 89a3ea1e..d3f7cdd6 100644 --- a/tests/snapshots/external/0b1372d7f7c057905f665ad506f3dd3bee62fb9b1c8b2a39991550e7845c2b02.html +++ b/tests/snapshots/external/5206643f1d7951daaeaddc1b7dece75a61dda67ec3cb7cf98b84cbb3383a4544.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

@@ -352,8 +358,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/f848d4a9e516beeb1b1719630e34aa243a093ccd362a63e33dbd6202ae8ab75d.html b/tests/snapshots/external/57e7bb4ad48c93b1b5cc23ab970136cacb75a7f501ab8e34ecc7b4770801bda5.html similarity index 96% rename from tests/snapshots/external/f848d4a9e516beeb1b1719630e34aa243a093ccd362a63e33dbd6202ae8ab75d.html rename to tests/snapshots/external/57e7bb4ad48c93b1b5cc23ab970136cacb75a7f501ab8e34ecc7b4770801bda5.html index 19c29b39..69f8bcbc 100644 --- a/tests/snapshots/external/f848d4a9e516beeb1b1719630e34aa243a093ccd362a63e33dbd6202ae8ab75d.html +++ b/tests/snapshots/external/57e7bb4ad48c93b1b5cc23ab970136cacb75a7f501ab8e34ecc7b4770801bda5.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/735fc6ffdb82ce35cdab2aed2389a630e4d2c7ad95308bc5c7a56a8a8930b37f.html b/tests/snapshots/external/59872531a0860f434ddbe20c6e9e328889493c8c50bab8fa88b4198fa0daca16.html similarity index 97% rename from tests/snapshots/external/735fc6ffdb82ce35cdab2aed2389a630e4d2c7ad95308bc5c7a56a8a8930b37f.html rename to tests/snapshots/external/59872531a0860f434ddbe20c6e9e328889493c8c50bab8fa88b4198fa0daca16.html index 44516fe5..d1aed71e 100644 --- a/tests/snapshots/external/735fc6ffdb82ce35cdab2aed2389a630e4d2c7ad95308bc5c7a56a8a8930b37f.html +++ b/tests/snapshots/external/59872531a0860f434ddbe20c6e9e328889493c8c50bab8fa88b4198fa0daca16.html @@ -16,8 +16,10 @@

- - Class + + + Class +

diff --git a/tests/snapshots/external/0fac4f5e7f455b351c60268567bfcbd0259b652d0534259efea7815aa15b1122.html b/tests/snapshots/external/5e331d13e0e018b70ff04f2a44ad2420d24b23716409c3e68d337c18d7693e3c.html similarity index 95% rename from tests/snapshots/external/0fac4f5e7f455b351c60268567bfcbd0259b652d0534259efea7815aa15b1122.html rename to tests/snapshots/external/5e331d13e0e018b70ff04f2a44ad2420d24b23716409c3e68d337c18d7693e3c.html index 47cfb56f..b460fff8 100644 --- a/tests/snapshots/external/0fac4f5e7f455b351c60268567bfcbd0259b652d0534259efea7815aa15b1122.html +++ b/tests/snapshots/external/5e331d13e0e018b70ff04f2a44ad2420d24b23716409c3e68d337c18d7693e3c.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/e6a9b76f268cde81a129e7273038db0ff3fcd73530442a30c48cf01dcbc30aaa.html b/tests/snapshots/external/76176ed54147e4fe03dce8d1cb3d5161252e300f3d2ce0106a5f3212dc765fc0.html similarity index 95% rename from tests/snapshots/external/e6a9b76f268cde81a129e7273038db0ff3fcd73530442a30c48cf01dcbc30aaa.html rename to tests/snapshots/external/76176ed54147e4fe03dce8d1cb3d5161252e300f3d2ce0106a5f3212dc765fc0.html index dbcf8c57..b11a32a9 100644 --- a/tests/snapshots/external/e6a9b76f268cde81a129e7273038db0ff3fcd73530442a30c48cf01dcbc30aaa.html +++ b/tests/snapshots/external/76176ed54147e4fe03dce8d1cb3d5161252e300f3d2ce0106a5f3212dc765fc0.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/fb65efbbfc3ef9c2a06e6f539f8a75bec4276e61254539632a1d5f8f2c6c3452.html b/tests/snapshots/external/7f570c4de561623d5c693568bb6d73b71798bf453db873712da5d624c70f96e0.html similarity index 95% rename from tests/snapshots/external/fb65efbbfc3ef9c2a06e6f539f8a75bec4276e61254539632a1d5f8f2c6c3452.html rename to tests/snapshots/external/7f570c4de561623d5c693568bb6d73b71798bf453db873712da5d624c70f96e0.html index 3cec9af8..6d65e9c4 100644 --- a/tests/snapshots/external/fb65efbbfc3ef9c2a06e6f539f8a75bec4276e61254539632a1d5f8f2c6c3452.html +++ b/tests/snapshots/external/7f570c4de561623d5c693568bb6d73b71798bf453db873712da5d624c70f96e0.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/ba51e100acd4f6ad91f1ef484aa5f1bd537e661588b1742d93d0a6543cc3592c.html b/tests/snapshots/external/8306095b18c418a88cf0b94186be5f3b157e1aba824bdbd6d6c43346c7809750.html similarity index 96% rename from tests/snapshots/external/ba51e100acd4f6ad91f1ef484aa5f1bd537e661588b1742d93d0a6543cc3592c.html rename to tests/snapshots/external/8306095b18c418a88cf0b94186be5f3b157e1aba824bdbd6d6c43346c7809750.html index b18eb50e..9587018b 100644 --- a/tests/snapshots/external/ba51e100acd4f6ad91f1ef484aa5f1bd537e661588b1742d93d0a6543cc3592c.html +++ b/tests/snapshots/external/8306095b18c418a88cf0b94186be5f3b157e1aba824bdbd6d6c43346c7809750.html @@ -21,8 +21,10 @@

- - Class + + + Class +

@@ -109,8 +111,10 @@

- - NestedClass + + + NestedClass +

@@ -227,8 +231,10 @@

- - Subclass + + + Subclass +

@@ -323,8 +329,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/cdc8126d78b690d11c09e3128df0f8d65379375a6bd390da30f5676bf2289cf2.html b/tests/snapshots/external/94faed07f27540a6d6b9eff68943740224c23491ddcc290c4241ecbe5b74cfcf.html similarity index 95% rename from tests/snapshots/external/cdc8126d78b690d11c09e3128df0f8d65379375a6bd390da30f5676bf2289cf2.html rename to tests/snapshots/external/94faed07f27540a6d6b9eff68943740224c23491ddcc290c4241ecbe5b74cfcf.html index 158c1ca5..69ac7f8f 100644 --- a/tests/snapshots/external/cdc8126d78b690d11c09e3128df0f8d65379375a6bd390da30f5676bf2289cf2.html +++ b/tests/snapshots/external/94faed07f27540a6d6b9eff68943740224c23491ddcc290c4241ecbe5b74cfcf.html @@ -21,8 +21,10 @@

- - Class + + + Class +

@@ -109,8 +111,10 @@

- - NestedClass + + + NestedClass +

@@ -227,8 +231,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/d1216ebf8e30ec559861678318efb45bef54a847517e5d90e130818c2a06b163.html b/tests/snapshots/external/9c7eeb0d7bfb42a320713d254bb98a1cfeacf5a9761aab1fc92bb7f0b36bb38a.html similarity index 97% rename from tests/snapshots/external/d1216ebf8e30ec559861678318efb45bef54a847517e5d90e130818c2a06b163.html rename to tests/snapshots/external/9c7eeb0d7bfb42a320713d254bb98a1cfeacf5a9761aab1fc92bb7f0b36bb38a.html index 65e87e01..4ca680ba 100644 --- a/tests/snapshots/external/d1216ebf8e30ec559861678318efb45bef54a847517e5d90e130818c2a06b163.html +++ b/tests/snapshots/external/9c7eeb0d7bfb42a320713d254bb98a1cfeacf5a9761aab1fc92bb7f0b36bb38a.html @@ -16,8 +16,10 @@

- - Class + + + Class +

diff --git a/tests/snapshots/external/ae74b5980f9b6996ed6e112d53168fde16c32d92bed42fb3193f98e0e3f04602.html b/tests/snapshots/external/adcc51aa0d87373e550fe674e5b0a1e0d7c991d7eae8e015f3bbc521dd28d888.html similarity index 96% rename from tests/snapshots/external/ae74b5980f9b6996ed6e112d53168fde16c32d92bed42fb3193f98e0e3f04602.html rename to tests/snapshots/external/adcc51aa0d87373e550fe674e5b0a1e0d7c991d7eae8e015f3bbc521dd28d888.html index 34123ecf..92ce0842 100644 --- a/tests/snapshots/external/ae74b5980f9b6996ed6e112d53168fde16c32d92bed42fb3193f98e0e3f04602.html +++ b/tests/snapshots/external/adcc51aa0d87373e550fe674e5b0a1e0d7c991d7eae8e015f3bbc521dd28d888.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/728c1344630190ac84514ebd8e5ae2d95ba8685e16d2c79749f675b5b2a6cea5.html b/tests/snapshots/external/adcecdb71c09dd487d8f656fb695279c09a015ee664219910ccbb9bf1202b7ab.html similarity index 95% rename from tests/snapshots/external/728c1344630190ac84514ebd8e5ae2d95ba8685e16d2c79749f675b5b2a6cea5.html rename to tests/snapshots/external/adcecdb71c09dd487d8f656fb695279c09a015ee664219910ccbb9bf1202b7ab.html index d6ac202a..ad4817fe 100644 --- a/tests/snapshots/external/728c1344630190ac84514ebd8e5ae2d95ba8685e16d2c79749f675b5b2a6cea5.html +++ b/tests/snapshots/external/adcecdb71c09dd487d8f656fb695279c09a015ee664219910ccbb9bf1202b7ab.html @@ -21,8 +21,10 @@

- - Class + + + Class +

@@ -109,8 +111,10 @@

- - NestedClass + + + NestedClass +

@@ -227,8 +231,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/b060b701543e5503dc848538a164e80480ab25f8885aa83b97776e6b0cc6b570.html b/tests/snapshots/external/b0761b5d88e07d14fa608cec8c01e1a73af18660dd23b607272e9158ad2aede8.html similarity index 96% rename from tests/snapshots/external/b060b701543e5503dc848538a164e80480ab25f8885aa83b97776e6b0cc6b570.html rename to tests/snapshots/external/b0761b5d88e07d14fa608cec8c01e1a73af18660dd23b607272e9158ad2aede8.html index 599197fe..3fc98686 100644 --- a/tests/snapshots/external/b060b701543e5503dc848538a164e80480ab25f8885aa83b97776e6b0cc6b570.html +++ b/tests/snapshots/external/b0761b5d88e07d14fa608cec8c01e1a73af18660dd23b607272e9158ad2aede8.html @@ -16,8 +16,10 @@

- - Class + + + Class +

diff --git a/tests/snapshots/external/e8be7a9b1410e40dac79fe0ee29d3036e707a177b2ba2bdad25a6998bec570b7.html b/tests/snapshots/external/bf3b380c0319092b073e3dabff4955b9d7389a262d7f0558165d61387b7f887e.html similarity index 96% rename from tests/snapshots/external/e8be7a9b1410e40dac79fe0ee29d3036e707a177b2ba2bdad25a6998bec570b7.html rename to tests/snapshots/external/bf3b380c0319092b073e3dabff4955b9d7389a262d7f0558165d61387b7f887e.html index 3dbd9879..8374346a 100644 --- a/tests/snapshots/external/e8be7a9b1410e40dac79fe0ee29d3036e707a177b2ba2bdad25a6998bec570b7.html +++ b/tests/snapshots/external/bf3b380c0319092b073e3dabff4955b9d7389a262d7f0558165d61387b7f887e.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

@@ -352,8 +358,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/46e56f39b10d1e8ee4017bc11457bf76d169fc80b3d3e465213671b7f6e548eb.html b/tests/snapshots/external/c90af3fe1d726f630844ce68dd91183d1cfb31c9eef4ac21c100228b0d19cd26.html similarity index 92% rename from tests/snapshots/external/46e56f39b10d1e8ee4017bc11457bf76d169fc80b3d3e465213671b7f6e548eb.html rename to tests/snapshots/external/c90af3fe1d726f630844ce68dd91183d1cfb31c9eef4ac21c100228b0d19cd26.html index 36f35fb4..03b4e633 100644 --- a/tests/snapshots/external/46e56f39b10d1e8ee4017bc11457bf76d169fc80b3d3e465213671b7f6e548eb.html +++ b/tests/snapshots/external/c90af3fe1d726f630844ce68dd91183d1cfb31c9eef4ac21c100228b0d19cd26.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -70,8 +72,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/a2c5be9bd5d1f0db3ff64b44353c1760f5eb69d7db6401da2f28518d0e8065c4.html b/tests/snapshots/external/ca8e03e3261a6eaf00b109b79396421c81d30b6ab9b35128c2413234cdd74a9d.html similarity index 95% rename from tests/snapshots/external/a2c5be9bd5d1f0db3ff64b44353c1760f5eb69d7db6401da2f28518d0e8065c4.html rename to tests/snapshots/external/ca8e03e3261a6eaf00b109b79396421c81d30b6ab9b35128c2413234cdd74a9d.html index 4738a584..bd2f4fa1 100644 --- a/tests/snapshots/external/a2c5be9bd5d1f0db3ff64b44353c1760f5eb69d7db6401da2f28518d0e8065c4.html +++ b/tests/snapshots/external/ca8e03e3261a6eaf00b109b79396421c81d30b6ab9b35128c2413234cdd74a9d.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/052c34f22e4c711b1f13f53085cdd5e8edcfae4bdc1d8cb7f2ff76cd1c46cce5.html b/tests/snapshots/external/d7988a46775aa0d97ef4b9d05e5cec6ad0db0717a5ddc52be94c7ce2dedbc5c2.html similarity index 92% rename from tests/snapshots/external/052c34f22e4c711b1f13f53085cdd5e8edcfae4bdc1d8cb7f2ff76cd1c46cce5.html rename to tests/snapshots/external/d7988a46775aa0d97ef4b9d05e5cec6ad0db0717a5ddc52be94c7ce2dedbc5c2.html index e1a7d15c..9bef0700 100644 --- a/tests/snapshots/external/052c34f22e4c711b1f13f53085cdd5e8edcfae4bdc1d8cb7f2ff76cd1c46cce5.html +++ b/tests/snapshots/external/d7988a46775aa0d97ef4b9d05e5cec6ad0db0717a5ddc52be94c7ce2dedbc5c2.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -70,8 +72,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/7c988c9e13efeadd20b911a95cc69973b715cceacdadefc540109aad3c274bde.html b/tests/snapshots/external/dc101bbf9385e5f25556acb7641e92e1d5f9450c9f33925abb47f75eec2a1fe8.html similarity index 96% rename from tests/snapshots/external/7c988c9e13efeadd20b911a95cc69973b715cceacdadefc540109aad3c274bde.html rename to tests/snapshots/external/dc101bbf9385e5f25556acb7641e92e1d5f9450c9f33925abb47f75eec2a1fe8.html index 10b98188..62b309b8 100644 --- a/tests/snapshots/external/7c988c9e13efeadd20b911a95cc69973b715cceacdadefc540109aad3c274bde.html +++ b/tests/snapshots/external/dc101bbf9385e5f25556acb7641e92e1d5f9450c9f33925abb47f75eec2a1fe8.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

@@ -354,8 +360,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/83119803338105f101311992d31947e4fcaf2c5a6c68cad6355d8611c1cc2e3f.html b/tests/snapshots/external/e22a354563213d5c11458d4fe9b413c50133e5180d4418ebc9d678d8720cc4ab.html similarity index 95% rename from tests/snapshots/external/83119803338105f101311992d31947e4fcaf2c5a6c68cad6355d8611c1cc2e3f.html rename to tests/snapshots/external/e22a354563213d5c11458d4fe9b413c50133e5180d4418ebc9d678d8720cc4ab.html index c9c637e4..cc03e404 100644 --- a/tests/snapshots/external/83119803338105f101311992d31947e4fcaf2c5a6c68cad6355d8611c1cc2e3f.html +++ b/tests/snapshots/external/e22a354563213d5c11458d4fe9b413c50133e5180d4418ebc9d678d8720cc4ab.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/981438492e387bc82b23f09e3c5e0b452db5a1ffd88e52479db2b52a170fd8f9.html b/tests/snapshots/external/e555bf966edd006a573aee2d4f287acfe0d2ac9a13539ec648a7bb4e880bc340.html similarity index 96% rename from tests/snapshots/external/981438492e387bc82b23f09e3c5e0b452db5a1ffd88e52479db2b52a170fd8f9.html rename to tests/snapshots/external/e555bf966edd006a573aee2d4f287acfe0d2ac9a13539ec648a7bb4e880bc340.html index 574ec87c..d316ec18 100644 --- a/tests/snapshots/external/981438492e387bc82b23f09e3c5e0b452db5a1ffd88e52479db2b52a170fd8f9.html +++ b/tests/snapshots/external/e555bf966edd006a573aee2d4f287acfe0d2ac9a13539ec648a7bb4e880bc340.html @@ -50,8 +50,10 @@

- - Class + + + Class +

@@ -138,8 +140,10 @@

- - NestedClass + + + NestedClass +

@@ -256,8 +260,10 @@

- - Subclass + + + Subclass +

@@ -352,8 +358,10 @@

- - NestedClass + + + NestedClass +

diff --git a/tests/snapshots/external/7d5fe66539191786245991395e77d8ba0bbb22330cb08eaec2e84159bde4159b.html b/tests/snapshots/external/f697469880cb00c78c0799bbfffa5d0fa636196df3794fdef406175594595105.html similarity index 96% rename from tests/snapshots/external/7d5fe66539191786245991395e77d8ba0bbb22330cb08eaec2e84159bde4159b.html rename to tests/snapshots/external/f697469880cb00c78c0799bbfffa5d0fa636196df3794fdef406175594595105.html index 23e38eeb..88e84ca4 100644 --- a/tests/snapshots/external/7d5fe66539191786245991395e77d8ba0bbb22330cb08eaec2e84159bde4159b.html +++ b/tests/snapshots/external/f697469880cb00c78c0799bbfffa5d0fa636196df3794fdef406175594595105.html @@ -52,8 +52,10 @@

- - Class + + + Class +

@@ -140,8 +142,10 @@

- - NestedClass + + + NestedClass +

@@ -258,8 +262,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/snapshots/external/a1167b14f5a71a283817bf5866d2bb0bd08bf23dc054c6f7938a04f42feab99d.html b/tests/snapshots/external/fa334e855708698dc6f742267279d32a4d914fe171447fdb5f10885d31c67d5f.html similarity index 94% rename from tests/snapshots/external/a1167b14f5a71a283817bf5866d2bb0bd08bf23dc054c6f7938a04f42feab99d.html rename to tests/snapshots/external/fa334e855708698dc6f742267279d32a4d914fe171447fdb5f10885d31c67d5f.html index bb9001d8..d4f6762f 100644 --- a/tests/snapshots/external/a1167b14f5a71a283817bf5866d2bb0bd08bf23dc054c6f7938a04f42feab99d.html +++ b/tests/snapshots/external/fa334e855708698dc6f742267279d32a4d914fe171447fdb5f10885d31c67d5f.html @@ -54,8 +54,10 @@

- - Class + + + Class +

@@ -72,8 +74,10 @@

- - Subclass + + + Subclass +

diff --git a/tests/test_handler.py b/tests/test_handler.py index 6c2381db..8ef5533e 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -167,7 +167,7 @@ def function(self): ) with temporary_visited_module(code) as module: # TODO: Remove once Griffe does that automatically. - module.lines_collection[module.filepath] = code.splitlines() # type: ignore[index] + module.lines_collection[module.filepath] = code.splitlines() module["Class"].lineno = None module["Class.function"].lineno = None diff --git a/tests/test_rendering.py b/tests/test_rendering.py index 081702f4..10456392 100644 --- a/tests/test_rendering.py +++ b/tests/test_rendering.py @@ -51,7 +51,7 @@ def test_format_signature(name: Markup, signature: str) -> None: signature: Signature to format. """ for length in (5, 100): - assert rendering._format_signature(name, signature, length) + assert rendering._format_signature(name, signature, "def", length) @dataclass @@ -76,7 +76,7 @@ def test_filter_objects(names: list[str], filter_params: dict[str, Any], expecte expected_names: Names expected to be kept. """ objects = {name: _FakeObject(name) for name in names} - filtered = rendering.do_filter_objects(objects, **filter_params) # type: ignore[arg-type] + filtered = rendering.do_filter_objects(objects, **filter_params) filtered_names = {obj.name for obj in filtered} assert set(filtered_names) == set(expected_names)