mkdocstrings-python 1.16.12__py3-none-any.whl → 1.18.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocstrings_handlers/python/__init__.py +4 -0
- mkdocstrings_handlers/python/_internal/config.py +140 -4
- mkdocstrings_handlers/python/_internal/handler.py +13 -4
- mkdocstrings_handlers/python/_internal/rendering.py +105 -8
- mkdocstrings_handlers/python/templates/material/_base/attribute.html.jinja +4 -2
- mkdocstrings_handlers/python/templates/material/_base/children.html.jinja +29 -4
- mkdocstrings_handlers/python/templates/material/_base/class.html.jinja +34 -22
- mkdocstrings_handlers/python/templates/material/_base/docstring/parameters.html.jinja +3 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html +10 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/type_aliases.html.jinja +86 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html +10 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring/type_parameters.html.jinja +208 -0
- mkdocstrings_handlers/python/templates/material/_base/docstring.html.jinja +6 -0
- mkdocstrings_handlers/python/templates/material/_base/expression.html.jinja +51 -1
- mkdocstrings_handlers/python/templates/material/_base/function.html.jinja +7 -3
- mkdocstrings_handlers/python/templates/material/_base/languages/en.html.jinja +11 -0
- mkdocstrings_handlers/python/templates/material/_base/languages/ja.html.jinja +12 -1
- mkdocstrings_handlers/python/templates/material/_base/languages/zh.html.jinja +12 -1
- mkdocstrings_handlers/python/templates/material/_base/module.html.jinja +2 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html +10 -0
- mkdocstrings_handlers/python/templates/material/_base/summary/type_aliases.html.jinja +24 -0
- mkdocstrings_handlers/python/templates/material/_base/summary.html.jinja +5 -0
- mkdocstrings_handlers/python/templates/material/_base/type_alias.html +10 -0
- mkdocstrings_handlers/python/templates/material/_base/type_alias.html.jinja +120 -0
- mkdocstrings_handlers/python/templates/material/_base/type_parameters.html +10 -0
- mkdocstrings_handlers/python/templates/material/_base/type_parameters.html.jinja +89 -0
- mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/type_aliases.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html +1 -0
- mkdocstrings_handlers/python/templates/material/docstring/type_parameters.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/style.css +35 -3
- mkdocstrings_handlers/python/templates/material/summary/type_aliases.html +1 -0
- mkdocstrings_handlers/python/templates/material/summary/type_aliases.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/type_alias.html +1 -0
- mkdocstrings_handlers/python/templates/material/type_alias.html.jinja +1 -0
- mkdocstrings_handlers/python/templates/material/type_parameters.html +1 -0
- mkdocstrings_handlers/python/templates/material/type_parameters.html.jinja +1 -0
- {mkdocstrings_python-1.16.12.dist-info → mkdocstrings_python-1.18.0.dist-info}/METADATA +3 -3
- {mkdocstrings_python-1.16.12.dist-info → mkdocstrings_python-1.18.0.dist-info}/RECORD +42 -22
- {mkdocstrings_python-1.16.12.dist-info → mkdocstrings_python-1.18.0.dist-info}/WHEEL +1 -1
- {mkdocstrings_python-1.16.12.dist-info → mkdocstrings_python-1.18.0.dist-info}/entry_points.txt +0 -0
- {mkdocstrings_python-1.16.12.dist-info → mkdocstrings_python-1.18.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -22,12 +22,14 @@ from mkdocstrings_handlers.python._internal.rendering import (
|
|
|
22
22
|
do_as_classes_section,
|
|
23
23
|
do_as_functions_section,
|
|
24
24
|
do_as_modules_section,
|
|
25
|
+
do_as_type_aliases_section,
|
|
25
26
|
do_backlink_tree,
|
|
26
27
|
do_crossref,
|
|
27
28
|
do_filter_objects,
|
|
28
29
|
do_format_attribute,
|
|
29
30
|
do_format_code,
|
|
30
31
|
do_format_signature,
|
|
32
|
+
do_format_type_alias,
|
|
31
33
|
do_get_template,
|
|
32
34
|
do_multi_crossref,
|
|
33
35
|
do_order_members,
|
|
@@ -55,12 +57,14 @@ __all__ = [
|
|
|
55
57
|
"do_as_classes_section",
|
|
56
58
|
"do_as_functions_section",
|
|
57
59
|
"do_as_modules_section",
|
|
60
|
+
"do_as_type_aliases_section",
|
|
58
61
|
"do_backlink_tree",
|
|
59
62
|
"do_crossref",
|
|
60
63
|
"do_filter_objects",
|
|
61
64
|
"do_format_attribute",
|
|
62
65
|
"do_format_code",
|
|
63
66
|
"do_format_signature",
|
|
67
|
+
"do_format_type_alias",
|
|
64
68
|
"do_get_template",
|
|
65
69
|
"do_multi_crossref",
|
|
66
70
|
"do_order_members",
|
|
@@ -186,6 +186,24 @@ class GoogleStyleOptions:
|
|
|
186
186
|
),
|
|
187
187
|
] = True
|
|
188
188
|
|
|
189
|
+
warn_missing_types: Annotated[
|
|
190
|
+
bool,
|
|
191
|
+
_Field(
|
|
192
|
+
group="docstrings",
|
|
193
|
+
parent="docstring_options",
|
|
194
|
+
description="Warn about missing type/annotation for parameters, return values, etc.",
|
|
195
|
+
),
|
|
196
|
+
] = True
|
|
197
|
+
|
|
198
|
+
warnings: Annotated[
|
|
199
|
+
bool,
|
|
200
|
+
_Field(
|
|
201
|
+
group="docstrings",
|
|
202
|
+
parent="docstring_options",
|
|
203
|
+
description="Generally enable/disable warnings when parsing docstrings.",
|
|
204
|
+
),
|
|
205
|
+
] = True
|
|
206
|
+
|
|
189
207
|
|
|
190
208
|
# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.
|
|
191
209
|
@dataclass(**_dataclass_options) # type: ignore[call-overload]
|
|
@@ -219,12 +237,57 @@ class NumpyStyleOptions:
|
|
|
219
237
|
),
|
|
220
238
|
] = True
|
|
221
239
|
|
|
240
|
+
warn_missing_types: Annotated[
|
|
241
|
+
bool,
|
|
242
|
+
_Field(
|
|
243
|
+
group="docstrings",
|
|
244
|
+
parent="docstring_options",
|
|
245
|
+
description="Warn about missing type/annotation for parameters, return values, etc.",
|
|
246
|
+
),
|
|
247
|
+
] = True
|
|
248
|
+
|
|
249
|
+
warnings: Annotated[
|
|
250
|
+
bool,
|
|
251
|
+
_Field(
|
|
252
|
+
group="docstrings",
|
|
253
|
+
parent="docstring_options",
|
|
254
|
+
description="Generally enable/disable warnings when parsing docstrings.",
|
|
255
|
+
),
|
|
256
|
+
] = True
|
|
257
|
+
|
|
222
258
|
|
|
223
259
|
# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.
|
|
224
260
|
@dataclass(**_dataclass_options) # type: ignore[call-overload]
|
|
225
261
|
class SphinxStyleOptions:
|
|
226
262
|
"""Sphinx style docstring options."""
|
|
227
263
|
|
|
264
|
+
warn_unknown_params: Annotated[
|
|
265
|
+
bool,
|
|
266
|
+
_Field(
|
|
267
|
+
group="docstrings",
|
|
268
|
+
parent="docstring_options",
|
|
269
|
+
description="Warn about documented parameters not appearing in the signature.",
|
|
270
|
+
),
|
|
271
|
+
] = True
|
|
272
|
+
|
|
273
|
+
warn_missing_types: Annotated[
|
|
274
|
+
bool,
|
|
275
|
+
_Field(
|
|
276
|
+
group="docstrings",
|
|
277
|
+
parent="docstring_options",
|
|
278
|
+
description="Warn about missing type/annotation for return values.",
|
|
279
|
+
),
|
|
280
|
+
] = True
|
|
281
|
+
|
|
282
|
+
warnings: Annotated[
|
|
283
|
+
bool,
|
|
284
|
+
_Field(
|
|
285
|
+
group="docstrings",
|
|
286
|
+
parent="docstring_options",
|
|
287
|
+
description="Generally enable/disable warnings when parsing docstrings.",
|
|
288
|
+
),
|
|
289
|
+
] = True
|
|
290
|
+
|
|
228
291
|
|
|
229
292
|
# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.
|
|
230
293
|
@dataclass(**_dataclass_options) # type: ignore[call-overload]
|
|
@@ -360,6 +423,15 @@ class SummaryOption:
|
|
|
360
423
|
),
|
|
361
424
|
] = False
|
|
362
425
|
|
|
426
|
+
type_aliases: Annotated[
|
|
427
|
+
bool,
|
|
428
|
+
_Field(
|
|
429
|
+
group="members",
|
|
430
|
+
parent="summary",
|
|
431
|
+
description="Whether to render summaries of type aliases.",
|
|
432
|
+
),
|
|
433
|
+
] = False
|
|
434
|
+
|
|
363
435
|
|
|
364
436
|
# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.
|
|
365
437
|
@dataclass(**_dataclass_options) # type: ignore[call-overload]
|
|
@@ -554,6 +626,14 @@ class PythonInputOptions:
|
|
|
554
626
|
),
|
|
555
627
|
] = False
|
|
556
628
|
|
|
629
|
+
overloads_only: Annotated[
|
|
630
|
+
bool,
|
|
631
|
+
_Field(
|
|
632
|
+
group="signatures",
|
|
633
|
+
description="Whether to hide the implementation signature if the overloads are shown.",
|
|
634
|
+
),
|
|
635
|
+
] = False
|
|
636
|
+
|
|
557
637
|
parameter_headings: Annotated[
|
|
558
638
|
bool,
|
|
559
639
|
_Field(
|
|
@@ -614,6 +694,14 @@ class PythonInputOptions:
|
|
|
614
694
|
),
|
|
615
695
|
] = False
|
|
616
696
|
|
|
697
|
+
show_attribute_values: Annotated[
|
|
698
|
+
bool,
|
|
699
|
+
_Field(
|
|
700
|
+
group="signatures",
|
|
701
|
+
description="Show initial values of attributes in classes.",
|
|
702
|
+
),
|
|
703
|
+
] = True
|
|
704
|
+
|
|
617
705
|
show_bases: Annotated[
|
|
618
706
|
bool,
|
|
619
707
|
_Field(
|
|
@@ -718,6 +806,22 @@ class PythonInputOptions:
|
|
|
718
806
|
),
|
|
719
807
|
] = True
|
|
720
808
|
|
|
809
|
+
show_docstring_type_aliases: Annotated[
|
|
810
|
+
bool,
|
|
811
|
+
_Field(
|
|
812
|
+
group="docstrings",
|
|
813
|
+
description="Whether to display the 'Type Aliases' section in the object's docstring.",
|
|
814
|
+
),
|
|
815
|
+
] = True
|
|
816
|
+
|
|
817
|
+
show_docstring_type_parameters: Annotated[
|
|
818
|
+
bool,
|
|
819
|
+
_Field(
|
|
820
|
+
group="docstrings",
|
|
821
|
+
description="Whether to display the 'Type Parameters' section in the object's docstring.",
|
|
822
|
+
),
|
|
823
|
+
] = True
|
|
824
|
+
|
|
721
825
|
show_docstring_warns: Annotated[
|
|
722
826
|
bool,
|
|
723
827
|
_Field(
|
|
@@ -809,6 +913,14 @@ class PythonInputOptions:
|
|
|
809
913
|
),
|
|
810
914
|
] = False
|
|
811
915
|
|
|
916
|
+
show_signature_type_parameters: Annotated[
|
|
917
|
+
bool,
|
|
918
|
+
_Field(
|
|
919
|
+
group="signatures",
|
|
920
|
+
description="Show the type parameters in generic classes, methods, functions and type aliases signatures.",
|
|
921
|
+
),
|
|
922
|
+
] = False
|
|
923
|
+
|
|
812
924
|
show_signature: Annotated[
|
|
813
925
|
bool,
|
|
814
926
|
_Field(
|
|
@@ -849,6 +961,14 @@ class PythonInputOptions:
|
|
|
849
961
|
),
|
|
850
962
|
] = False
|
|
851
963
|
|
|
964
|
+
skip_local_inventory: Annotated[
|
|
965
|
+
bool,
|
|
966
|
+
_Field(
|
|
967
|
+
group="general",
|
|
968
|
+
description="Whether to prevent objects from being registered in the local objects inventory.",
|
|
969
|
+
),
|
|
970
|
+
] = False
|
|
971
|
+
|
|
852
972
|
signature_crossrefs: Annotated[
|
|
853
973
|
bool,
|
|
854
974
|
_Field(
|
|
@@ -873,6 +993,14 @@ class PythonInputOptions:
|
|
|
873
993
|
),
|
|
874
994
|
] = ""
|
|
875
995
|
|
|
996
|
+
type_parameter_headings: Annotated[
|
|
997
|
+
bool,
|
|
998
|
+
_Field(
|
|
999
|
+
group="headings",
|
|
1000
|
+
description="Whether to render headings for type parameters (therefore showing type parameters in the ToC).",
|
|
1001
|
+
),
|
|
1002
|
+
] = False
|
|
1003
|
+
|
|
876
1004
|
unwrap_annotated: Annotated[
|
|
877
1005
|
bool,
|
|
878
1006
|
_Field(
|
|
@@ -914,9 +1042,15 @@ class PythonInputOptions:
|
|
|
914
1042
|
if "summary" in data:
|
|
915
1043
|
summary = data["summary"]
|
|
916
1044
|
if summary is True:
|
|
917
|
-
summary = SummaryOption(attributes=True, functions=True, classes=True, modules=True)
|
|
1045
|
+
summary = SummaryOption(attributes=True, functions=True, classes=True, modules=True, type_aliases=True)
|
|
918
1046
|
elif summary is False:
|
|
919
|
-
summary = SummaryOption(
|
|
1047
|
+
summary = SummaryOption(
|
|
1048
|
+
attributes=False,
|
|
1049
|
+
functions=False,
|
|
1050
|
+
classes=False,
|
|
1051
|
+
modules=False,
|
|
1052
|
+
type_aliases=False,
|
|
1053
|
+
)
|
|
920
1054
|
else:
|
|
921
1055
|
summary = SummaryOption(**summary)
|
|
922
1056
|
data["summary"] = summary
|
|
@@ -941,7 +1075,7 @@ class PythonOptions(PythonInputOptions): # type: ignore[override,unused-ignore]
|
|
|
941
1075
|
"""A list of filters, or `"public"`."""
|
|
942
1076
|
|
|
943
1077
|
summary: SummaryOption = field(default_factory=SummaryOption)
|
|
944
|
-
"""Whether to render summaries of modules, classes, functions (methods) and
|
|
1078
|
+
"""Whether to render summaries of modules, classes, functions (methods), attributes and type aliases."""
|
|
945
1079
|
|
|
946
1080
|
@classmethod
|
|
947
1081
|
def coerce(cls, **data: Any) -> MutableMapping[str, Any]:
|
|
@@ -1019,7 +1153,9 @@ class PythonInputConfig:
|
|
|
1019
1153
|
|
|
1020
1154
|
locale: Annotated[
|
|
1021
1155
|
str | None,
|
|
1022
|
-
_Field(
|
|
1156
|
+
_Field(
|
|
1157
|
+
description="Deprecated. Use mkdocstrings' own `locale` setting instead. The locale to use when translating template strings.",
|
|
1158
|
+
),
|
|
1023
1159
|
] = None
|
|
1024
1160
|
|
|
1025
1161
|
@classmethod
|
|
@@ -278,12 +278,13 @@ class PythonHandler(BaseHandler):
|
|
|
278
278
|
|
|
279
279
|
return doc_object
|
|
280
280
|
|
|
281
|
-
def render(self, data: CollectorItem, options: PythonOptions) -> str:
|
|
281
|
+
def render(self, data: CollectorItem, options: PythonOptions, locale: str | None = None) -> str:
|
|
282
282
|
"""Render the collected data.
|
|
283
283
|
|
|
284
284
|
Parameters:
|
|
285
285
|
data: The collected data.
|
|
286
286
|
options: The options to use for rendering.
|
|
287
|
+
locale: The locale to use for rendering (default is "en").
|
|
287
288
|
|
|
288
289
|
Returns:
|
|
289
290
|
The rendered data (HTML).
|
|
@@ -300,7 +301,8 @@ class PythonHandler(BaseHandler):
|
|
|
300
301
|
# than as an item in a dictionary.
|
|
301
302
|
"heading_level": options.heading_level,
|
|
302
303
|
"root": True,
|
|
303
|
-
"
|
|
304
|
+
# YORE: Bump 2: Regex-replace ` or .+` with ` or "en",` within line.
|
|
305
|
+
"locale": locale or self.config.locale,
|
|
304
306
|
},
|
|
305
307
|
)
|
|
306
308
|
|
|
@@ -320,12 +322,14 @@ class PythonHandler(BaseHandler):
|
|
|
320
322
|
self.env.filters["format_code"] = rendering.do_format_code
|
|
321
323
|
self.env.filters["format_signature"] = rendering.do_format_signature
|
|
322
324
|
self.env.filters["format_attribute"] = rendering.do_format_attribute
|
|
325
|
+
self.env.filters["format_type_alias"] = rendering.do_format_type_alias
|
|
323
326
|
self.env.filters["filter_objects"] = rendering.do_filter_objects
|
|
324
327
|
self.env.filters["stash_crossref"] = rendering.do_stash_crossref
|
|
325
328
|
self.env.filters["get_template"] = rendering.do_get_template
|
|
326
329
|
self.env.filters["as_attributes_section"] = rendering.do_as_attributes_section
|
|
327
330
|
self.env.filters["as_functions_section"] = rendering.do_as_functions_section
|
|
328
331
|
self.env.filters["as_classes_section"] = rendering.do_as_classes_section
|
|
332
|
+
self.env.filters["as_type_aliases_section"] = rendering.do_as_type_aliases_section
|
|
329
333
|
self.env.filters["as_modules_section"] = rendering.do_as_modules_section
|
|
330
334
|
self.env.filters["backlink_tree"] = rendering.do_backlink_tree
|
|
331
335
|
self.env.globals["AutorefsHook"] = rendering.AutorefsHook
|
|
@@ -360,7 +364,7 @@ class PythonHandler(BaseHandler):
|
|
|
360
364
|
return tuple(f"{alias}({parameter})" for alias in aliases)
|
|
361
365
|
return tuple(aliases)
|
|
362
366
|
|
|
363
|
-
def normalize_extension_paths(self, extensions: Sequence) ->
|
|
367
|
+
def normalize_extension_paths(self, extensions: Sequence) -> list[str | dict[str, Any]]:
|
|
364
368
|
"""Resolve extension paths relative to config file.
|
|
365
369
|
|
|
366
370
|
Parameters:
|
|
@@ -369,7 +373,7 @@ class PythonHandler(BaseHandler):
|
|
|
369
373
|
Returns:
|
|
370
374
|
The normalized extensions.
|
|
371
375
|
"""
|
|
372
|
-
normalized = []
|
|
376
|
+
normalized: list[str | dict[str, Any]] = []
|
|
373
377
|
|
|
374
378
|
for ext in extensions:
|
|
375
379
|
if isinstance(ext, dict):
|
|
@@ -401,10 +405,15 @@ def get_handler(
|
|
|
401
405
|
Parameters:
|
|
402
406
|
handler_config: The handler configuration.
|
|
403
407
|
tool_config: The tool (SSG) configuration.
|
|
408
|
+
**kwargs: Additional arguments to pass to the handler.
|
|
404
409
|
|
|
405
410
|
Returns:
|
|
406
411
|
An instance of `PythonHandler`.
|
|
407
412
|
"""
|
|
413
|
+
# In rare cases, Griffe hits the recursion limit because of deeply-nested ASTs.
|
|
414
|
+
# We therefore increase the limit here, once, before Griffe is used to collect or render stuff.
|
|
415
|
+
sys.setrecursionlimit(max(sys.getrecursionlimit(), 2000))
|
|
416
|
+
|
|
408
417
|
base_dir = Path(tool_config.config_file_path or "./mkdocs.yml").parent
|
|
409
418
|
if "inventories" not in handler_config and "import" in handler_config:
|
|
410
419
|
warn("The 'import' key is renamed 'inventories' for the Python handler", FutureWarning, stacklevel=1)
|
|
@@ -28,7 +28,10 @@ from griffe import (
|
|
|
28
28
|
DocstringSectionClasses,
|
|
29
29
|
DocstringSectionFunctions,
|
|
30
30
|
DocstringSectionModules,
|
|
31
|
+
DocstringSectionTypeAliases,
|
|
32
|
+
DocstringTypeAlias,
|
|
31
33
|
Object,
|
|
34
|
+
TypeAlias,
|
|
32
35
|
)
|
|
33
36
|
from jinja2 import TemplateNotFound, pass_context, pass_environment
|
|
34
37
|
from markupsafe import Markup
|
|
@@ -160,8 +163,10 @@ def do_format_signature(
|
|
|
160
163
|
The same code, formatted.
|
|
161
164
|
"""
|
|
162
165
|
env = context.environment
|
|
166
|
+
# YORE: Bump 2: Replace `do_get_template(env, "type_parameters")` with `"type_parameters.html.jinja"` within line.
|
|
167
|
+
type_params_template = env.get_template(do_get_template(env, "type_parameters"))
|
|
163
168
|
# YORE: Bump 2: Replace `do_get_template(env, "signature")` with `"signature.html.jinja"` within line.
|
|
164
|
-
|
|
169
|
+
signature_template = env.get_template(do_get_template(env, "signature"))
|
|
165
170
|
|
|
166
171
|
if annotations is None:
|
|
167
172
|
new_context = context.parent
|
|
@@ -169,7 +174,9 @@ def do_format_signature(
|
|
|
169
174
|
new_context = dict(context.parent)
|
|
170
175
|
new_context["config"] = replace(new_context["config"], show_signature_annotations=annotations)
|
|
171
176
|
|
|
172
|
-
signature =
|
|
177
|
+
signature = type_params_template.render(context.parent, obj=function, signature=True)
|
|
178
|
+
signature += signature_template.render(new_context, function=function, signature=True)
|
|
179
|
+
|
|
173
180
|
signature = _format_signature(callable_path, signature, line_length)
|
|
174
181
|
signature = str(
|
|
175
182
|
env.filters["highlight"](
|
|
@@ -208,6 +215,7 @@ def do_format_attribute(
|
|
|
208
215
|
line_length: int,
|
|
209
216
|
*,
|
|
210
217
|
crossrefs: bool = False, # noqa: ARG001
|
|
218
|
+
show_value: bool = True,
|
|
211
219
|
) -> str:
|
|
212
220
|
"""Format an attribute.
|
|
213
221
|
|
|
@@ -235,7 +243,7 @@ def do_format_attribute(
|
|
|
235
243
|
backlink_type="returned-by",
|
|
236
244
|
)
|
|
237
245
|
signature += f": {annotation}"
|
|
238
|
-
if attribute.value:
|
|
246
|
+
if show_value and attribute.value:
|
|
239
247
|
value = template.render(context.parent, expression=attribute.value, signature=True, backlink_type="used-by")
|
|
240
248
|
signature += f" = {value}"
|
|
241
249
|
|
|
@@ -258,10 +266,71 @@ def do_format_attribute(
|
|
|
258
266
|
return signature
|
|
259
267
|
|
|
260
268
|
|
|
269
|
+
@pass_context
|
|
270
|
+
def do_format_type_alias(
|
|
271
|
+
context: Context,
|
|
272
|
+
type_alias_path: Markup,
|
|
273
|
+
type_alias: TypeAlias,
|
|
274
|
+
line_length: int,
|
|
275
|
+
*,
|
|
276
|
+
crossrefs: bool = False, # noqa: ARG001
|
|
277
|
+
) -> str:
|
|
278
|
+
"""Format a type alias.
|
|
279
|
+
|
|
280
|
+
Parameters:
|
|
281
|
+
context: Jinja context, passed automatically.
|
|
282
|
+
type_alias_path: The path of the type alias we render the signature of.
|
|
283
|
+
type_alias: The type alias we render the signature of.
|
|
284
|
+
line_length: The line length.
|
|
285
|
+
crossrefs: Whether to cross-reference types in the signature.
|
|
286
|
+
|
|
287
|
+
Returns:
|
|
288
|
+
The same code, formatted.
|
|
289
|
+
"""
|
|
290
|
+
env = context.environment
|
|
291
|
+
# YORE: Bump 2: Replace `do_get_template(env, "type_parameters")` with `"type_parameters.html.jinja"` within line.
|
|
292
|
+
type_params_template = env.get_template(do_get_template(env, "type_parameters"))
|
|
293
|
+
# YORE: Bump 2: Replace `do_get_template(env, "expression")` with `"expression.html.jinja"` within line.
|
|
294
|
+
expr_template = env.get_template(do_get_template(env, "expression"))
|
|
295
|
+
|
|
296
|
+
signature = str(type_alias_path).strip()
|
|
297
|
+
signature += type_params_template.render(context.parent, obj=type_alias, signature=True)
|
|
298
|
+
value = expr_template.render(context.parent, expression=type_alias.value, signature=True)
|
|
299
|
+
signature += f" = {value}"
|
|
300
|
+
|
|
301
|
+
signature = do_format_code(signature, line_length)
|
|
302
|
+
signature = str(
|
|
303
|
+
env.filters["highlight"](
|
|
304
|
+
Markup.escape(signature),
|
|
305
|
+
language="python",
|
|
306
|
+
inline=False,
|
|
307
|
+
classes=["doc-signature"],
|
|
308
|
+
linenums=False,
|
|
309
|
+
),
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
# Since we highlight the signature without `type`,
|
|
313
|
+
# Pygments sees only an assignment, not a type alias definition
|
|
314
|
+
# (at the moment it does not understand type alias definitions anyway).
|
|
315
|
+
# The result is that the type alias name is not parsed as such,
|
|
316
|
+
# but instead as a regular name: `n` CSS class instead of `nc`.
|
|
317
|
+
# To fix it, we replace the first occurrence of an `n` CSS class
|
|
318
|
+
# with an `nc` one, unless we found `nc` already.
|
|
319
|
+
if not re.search(r'<span class="nc">', signature):
|
|
320
|
+
signature = re.sub(r'<span class="[a-z]{1,2}">', '<span class="nc">', signature, count=1)
|
|
321
|
+
|
|
322
|
+
if stash := env.filters["stash_crossref"].stash:
|
|
323
|
+
for key, value in stash.items():
|
|
324
|
+
signature = re.sub(rf"\b{key}\b", value, signature)
|
|
325
|
+
stash.clear()
|
|
326
|
+
|
|
327
|
+
return signature
|
|
328
|
+
|
|
329
|
+
|
|
261
330
|
def do_order_members(
|
|
262
331
|
members: Sequence[Object | Alias],
|
|
263
332
|
order: Order | list[Order],
|
|
264
|
-
members_list: bool | list[str] | None,
|
|
333
|
+
members_list: bool | list[str] | None, # noqa: FBT001
|
|
265
334
|
) -> Sequence[Object | Alias]:
|
|
266
335
|
"""Order members given an ordering method.
|
|
267
336
|
|
|
@@ -522,7 +591,7 @@ def _get_formatter() -> Callable[[str, int], str]:
|
|
|
522
591
|
|
|
523
592
|
def _get_ruff_formatter() -> Callable[[str, int], str] | None:
|
|
524
593
|
try:
|
|
525
|
-
from ruff.__main__ import find_ruff_bin
|
|
594
|
+
from ruff.__main__ import find_ruff_bin # noqa: PLC0415
|
|
526
595
|
except ImportError:
|
|
527
596
|
return None
|
|
528
597
|
|
|
@@ -558,7 +627,7 @@ def _get_ruff_formatter() -> Callable[[str, int], str] | None:
|
|
|
558
627
|
|
|
559
628
|
def _get_black_formatter() -> Callable[[str, int], str] | None:
|
|
560
629
|
try:
|
|
561
|
-
from black import InvalidInput, Mode, format_str
|
|
630
|
+
from black import InvalidInput, Mode, format_str # noqa: PLC0415
|
|
562
631
|
except ModuleNotFoundError:
|
|
563
632
|
return None
|
|
564
633
|
|
|
@@ -591,7 +660,7 @@ def do_get_template(env: Environment, obj: str | Object) -> str:
|
|
|
591
660
|
extra_data = getattr(obj, "extra", {}).get("mkdocstrings", {})
|
|
592
661
|
if name := extra_data.get("template", ""):
|
|
593
662
|
return name
|
|
594
|
-
name = obj.kind.value
|
|
663
|
+
name = obj.kind.value.replace(" ", "_")
|
|
595
664
|
# YORE: Bump 2: Replace block with `return f"{name}.html.jinja"`.
|
|
596
665
|
try:
|
|
597
666
|
template = env.get_template(f"{name}.html")
|
|
@@ -638,7 +707,7 @@ def do_as_attributes_section(
|
|
|
638
707
|
name=attribute.name,
|
|
639
708
|
description=_parse_docstring_summary(attribute),
|
|
640
709
|
annotation=attribute.annotation,
|
|
641
|
-
value=attribute.value,
|
|
710
|
+
value=attribute.value,
|
|
642
711
|
)
|
|
643
712
|
for attribute in attributes
|
|
644
713
|
if not check_public or attribute.is_public
|
|
@@ -731,6 +800,34 @@ def do_as_modules_section(
|
|
|
731
800
|
)
|
|
732
801
|
|
|
733
802
|
|
|
803
|
+
@pass_context
|
|
804
|
+
def do_as_type_aliases_section(
|
|
805
|
+
context: Context, # noqa: ARG001
|
|
806
|
+
type_aliases: Sequence[TypeAlias],
|
|
807
|
+
*,
|
|
808
|
+
check_public: bool = True,
|
|
809
|
+
) -> DocstringSectionTypeAliases:
|
|
810
|
+
"""Build a type aliases section from a list of type aliases.
|
|
811
|
+
|
|
812
|
+
Parameters:
|
|
813
|
+
type_aliases: The type aliases to build the section from.
|
|
814
|
+
check_public: Whether to check if the type_alias is public.
|
|
815
|
+
|
|
816
|
+
Returns:
|
|
817
|
+
A type aliases docstring section.
|
|
818
|
+
"""
|
|
819
|
+
return DocstringSectionTypeAliases(
|
|
820
|
+
[
|
|
821
|
+
DocstringTypeAlias(
|
|
822
|
+
name=type_alias.name,
|
|
823
|
+
description=type_alias.docstring.value.split("\n", 1)[0] if type_alias.docstring else "",
|
|
824
|
+
)
|
|
825
|
+
for type_alias in type_aliases
|
|
826
|
+
if not check_public or type_alias.is_public
|
|
827
|
+
],
|
|
828
|
+
)
|
|
829
|
+
|
|
830
|
+
|
|
734
831
|
class AutorefsHook(AutorefsHookInterface):
|
|
735
832
|
"""Autorefs hook.
|
|
736
833
|
|
|
@@ -40,6 +40,7 @@ Context:
|
|
|
40
40
|
id=html_id,
|
|
41
41
|
class="doc doc-heading",
|
|
42
42
|
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute.name),
|
|
43
|
+
skip_inventory=config.skip_local_inventory,
|
|
43
44
|
) %}
|
|
44
45
|
|
|
45
46
|
{% block heading scoped %}
|
|
@@ -55,7 +56,7 @@ Context:
|
|
|
55
56
|
{% else %}
|
|
56
57
|
{%+ filter highlight(language="python", inline=True) %}
|
|
57
58
|
{{ attribute_name }}{% if attribute.annotation and config.show_signature_annotations %}: {{ attribute.annotation }}{% endif %}
|
|
58
|
-
{% if attribute.value %} = {{ attribute.value }}{% endif %}
|
|
59
|
+
{% if config.show_attribute_values and attribute.value %} = {{ attribute.value }}{% endif %}
|
|
59
60
|
{% endfilter %}
|
|
60
61
|
{% endif %}
|
|
61
62
|
{% endblock heading %}
|
|
@@ -79,7 +80,7 @@ Context:
|
|
|
79
80
|
This block renders the signature for the attribute.
|
|
80
81
|
-#}
|
|
81
82
|
{% if config.separate_signature %}
|
|
82
|
-
{% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs) %}
|
|
83
|
+
{% filter format_attribute(attribute, config.line_length, crossrefs=config.signature_crossrefs, show_value=config.show_attribute_values) %}
|
|
83
84
|
{{ attribute.name }}
|
|
84
85
|
{% endfilter %}
|
|
85
86
|
{% endif %}
|
|
@@ -93,6 +94,7 @@ Context:
|
|
|
93
94
|
id=html_id,
|
|
94
95
|
toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-attribute"></code> '|safe if config.show_symbol_type_toc else '') + (config.toc_label if config.toc_label and root else attribute_name),
|
|
95
96
|
hidden=True,
|
|
97
|
+
skip_inventory=config.skip_local_inventory,
|
|
96
98
|
) %}
|
|
97
99
|
{% endfilter %}
|
|
98
100
|
{% endif %}
|
|
@@ -45,7 +45,7 @@ Context:
|
|
|
45
45
|
) %}
|
|
46
46
|
{% if attributes %}
|
|
47
47
|
{% if config.show_category_heading %}
|
|
48
|
-
{% filter heading(heading_level, id=html_id ~ "-attributes") %}Attributes{% endfilter %}
|
|
48
|
+
{% filter heading(heading_level, id=html_id ~ "-attributes", skip_inventory=config.skip_local_inventory) %}Attributes{% endfilter %}
|
|
49
49
|
{% endif %}
|
|
50
50
|
{% with heading_level = heading_level + extra_level %}
|
|
51
51
|
{% for attribute in attributes|order_members(config.members_order, members_list) %}
|
|
@@ -57,6 +57,26 @@ Context:
|
|
|
57
57
|
{% endif %}
|
|
58
58
|
{% endwith %}
|
|
59
59
|
|
|
60
|
+
{% with type_aliases = obj.type_aliases|filter_objects(
|
|
61
|
+
filters=config.filters,
|
|
62
|
+
members_list=members_list,
|
|
63
|
+
inherited_members=config.inherited_members,
|
|
64
|
+
keep_no_docstrings=config.show_if_no_docstring,
|
|
65
|
+
) %}
|
|
66
|
+
{% if type_aliases %}
|
|
67
|
+
{% if config.show_category_heading %}
|
|
68
|
+
{% filter heading(heading_level, id=html_id ~ "-type_aliases") %}Type Aliases{% endfilter %}
|
|
69
|
+
{% endif %}
|
|
70
|
+
{% with heading_level = heading_level + extra_level %}
|
|
71
|
+
{% for type_alias in type_aliases|order_members(config.members_order, members_list) %}
|
|
72
|
+
{% if config.filters == "public" or members_list is not none or (not type_alias.is_imported or type_alias.is_public) %}
|
|
73
|
+
{% include type_alias|get_template with context %}
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% endfor %}
|
|
76
|
+
{% endwith %}
|
|
77
|
+
{% endif %}
|
|
78
|
+
{% endwith %}
|
|
79
|
+
|
|
60
80
|
{% with classes = obj.classes|filter_objects(
|
|
61
81
|
filters=config.filters,
|
|
62
82
|
members_list=members_list,
|
|
@@ -65,7 +85,7 @@ Context:
|
|
|
65
85
|
) %}
|
|
66
86
|
{% if classes %}
|
|
67
87
|
{% if config.show_category_heading %}
|
|
68
|
-
{% filter heading(heading_level, id=html_id ~ "-classes") %}Classes{% endfilter %}
|
|
88
|
+
{% filter heading(heading_level, id=html_id ~ "-classes", skip_inventory=config.skip_local_inventory) %}Classes{% endfilter %}
|
|
69
89
|
{% endif %}
|
|
70
90
|
{% with heading_level = heading_level + extra_level %}
|
|
71
91
|
{% for class in classes|order_members(config.members_order, members_list) %}
|
|
@@ -85,7 +105,7 @@ Context:
|
|
|
85
105
|
) %}
|
|
86
106
|
{% if functions %}
|
|
87
107
|
{% if config.show_category_heading %}
|
|
88
|
-
{% filter heading(heading_level, id=html_id ~ "-functions") %}Functions{% endfilter %}
|
|
108
|
+
{% filter heading(heading_level, id=html_id ~ "-functions", skip_inventory=config.skip_local_inventory) %}Functions{% endfilter %}
|
|
89
109
|
{% endif %}
|
|
90
110
|
{% with heading_level = heading_level + extra_level %}
|
|
91
111
|
{% for function in functions|order_members(config.members_order, members_list) %}
|
|
@@ -108,7 +128,7 @@ Context:
|
|
|
108
128
|
) %}
|
|
109
129
|
{% if modules %}
|
|
110
130
|
{% if config.show_category_heading %}
|
|
111
|
-
{% filter heading(heading_level, id=html_id ~ "-modules") %}Modules{% endfilter %}
|
|
131
|
+
{% filter heading(heading_level, id=html_id ~ "-modules", skip_inventory=config.skip_local_inventory) %}Modules{% endfilter %}
|
|
112
132
|
{% endif %}
|
|
113
133
|
{% with heading_level = heading_level + extra_level %}
|
|
114
134
|
{% for module in modules|order_members("alphabetical", members_list) %}
|
|
@@ -143,6 +163,11 @@ Context:
|
|
|
143
163
|
{% include attribute|get_template with context %}
|
|
144
164
|
{% endwith %}
|
|
145
165
|
|
|
166
|
+
{% elif child.is_type_alias %}
|
|
167
|
+
{% with type_alias = child %}
|
|
168
|
+
{% include type_alias|get_template with context %}
|
|
169
|
+
{% endwith %}
|
|
170
|
+
|
|
146
171
|
{% elif child.is_class %}
|
|
147
172
|
{% with class = child %}
|
|
148
173
|
{% include class|get_template with context %}
|