|
23 | 23 | import sys
|
24 | 24 | from pathlib import Path
|
25 | 25 | from types import ModuleType
|
26 |
| -from typing import Any, Optional, TypeVar, Union |
| 26 | +from typing import Optional |
27 | 27 | from unittest import mock
|
28 | 28 |
|
29 |
| -import sphinx.config |
30 | 29 | import sphobjinv
|
31 | 30 | import tqdm
|
32 |
| -from jax.typing import ArrayLike |
33 |
| -from sphinx_autodoc_typehints import format_annotation as default_format_annotation |
34 | 31 |
|
35 | 32 | # https://docs.github.com/en/actions/learn-github-actions/variables,
|
36 | 33 | # see the "Default environment variables" section
|
|
78 | 75 | # -- General configuration ---------------------------------------------------
|
79 | 76 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
80 | 77 |
|
81 |
| -# pylint: disable=invalid-name |
82 |
| -# Fixes ISSUE #561 pending a fix for ISSUE #570 |
83 |
| -show_warning_types = True |
84 |
| -suppress_warnings = ["config.cache"] |
85 |
| -# pylint: enable=invalid-name |
86 | 78 |
|
87 | 79 | # sphinx extensions
|
88 | 80 | extensions = [
|
|
216 | 208 | ("py:class", r"jaxtyping\.Shaped\[Array, '.*']"),
|
217 | 209 | ]
|
218 | 210 |
|
219 |
| -autodoc_custom_types: dict[Any, str] = { # Specify custom types for autodoc_type_hints |
220 |
| - ArrayLike: ":data:`~jax.typing.ArrayLike`", |
221 |
| -} |
222 |
| - |
223 | 211 | # custom references for tqdm, which does not support intersphinx
|
224 | 212 | tqdm_refs: dict[str, dict[str, str]] = {
|
225 | 213 | "py:class": {
|
226 | 214 | "tqdm.tqdm": "tqdm/#tqdm-objects",
|
227 | 215 | }
|
228 | 216 | }
|
229 | 217 |
|
230 |
| - |
231 |
| -def typehints_formatter( |
232 |
| - annotation: Any, config: sphinx.config.Config |
233 |
| -) -> Union[str, None]: |
234 |
| - """ |
235 |
| - Properly replace custom type aliases. |
236 |
| -
|
237 |
| - :param annotation: The type annotation to be processed. |
238 |
| - :param config: The current configuration being used. |
239 |
| - :returns: A string of reStructured text (e.g. :py:class:`something`) or None to fall |
240 |
| - back to the default. |
241 |
| -
|
242 |
| - This function is called on each type annotation that Sphinx processes. |
243 |
| - The following steps occur: |
244 |
| -
|
245 |
| - 1. Check if the annotation is a TypeVar. If so, replace it with its "bound" type |
246 |
| - for clarity in the docs. If not, then replace it with typing.Any. |
247 |
| - 2. Check whether a specific Sphinx string has been defined in autodoc_custom_types. |
248 |
| - If so, return that. |
249 |
| - 3. If not, then return None, which uses thee default formatter. |
250 |
| -
|
251 |
| - See https://github.com/tox-dev/sphinx-autodoc-typehints?tab=readme-ov-file#options |
252 |
| - for specification. |
253 |
| - """ |
254 |
| - if isinstance(annotation, TypeVar): |
255 |
| - if annotation.__bound__ is None: # when a generic TypeVar has been used. |
256 |
| - return default_format_annotation(Any, config) |
257 |
| - return default_format_annotation( |
258 |
| - annotation.__bound__, config |
259 |
| - ) # get the annotation for the bound type |
260 |
| - return autodoc_custom_types.get(annotation) |
261 |
| - |
262 |
| - |
263 | 218 | # -- Options for HTML output -------------------------------------------------
|
264 | 219 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
265 | 220 |
|
|
0 commit comments