Skip to content

Commit d04d73a

Browse files
committed
fix(docs): remove typehints_formatter.
By removing the `typehints_formatter` we are able to resolve issues #570 and #734. The former issue is resolved by removing the non-picklable function, which enables build caching, and the second is solved by removing the `TypeVar` bound replacement. While the `TypeVar` replacement does provide more concise documentation, it removes a key piece of information, which the reader must be aware of. For example, in: ```python T = TypeVar("T", bound=Data) def typevar(a: T, b: T) -> None: ... def bound(a: Data, b: Data): ... def valid(a: SupervisedData, b: SupervisedData): ... def invalid(a: Data, b: SupervisedData): ... ``` the `typevar` function is the actual specification, `bound` is the documented specification, `valid` is a valid specification, and `invalid` is an invalid specification which is presented as valid in the documentation (if we replace the `TypeVar` with the bound). As an additional comment, we do now lose the functionality of the `autodoc_custom_types` -- it should be noted that the `ArrayLike` custom type (the only listed custom type) doesn't appear to be used anywhere in the codebase. Refs: #570, #734
1 parent 94fc03c commit d04d73a

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

Diff for: documentation/source/conf.py

-42
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@
7878
# -- General configuration ---------------------------------------------------
7979
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
8080

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
8681

8782
# sphinx extensions
8883
extensions = [
@@ -216,50 +211,13 @@
216211
("py:class", r"jaxtyping\.Shaped\[Array, '.*']"),
217212
]
218213

219-
autodoc_custom_types: dict[Any, str] = { # Specify custom types for autodoc_type_hints
220-
ArrayLike: ":data:`~jax.typing.ArrayLike`",
221-
}
222-
223214
# custom references for tqdm, which does not support intersphinx
224215
tqdm_refs: dict[str, dict[str, str]] = {
225216
"py:class": {
226217
"tqdm.tqdm": "tqdm/#tqdm-objects",
227218
}
228219
}
229220

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-
263221
# -- Options for HTML output -------------------------------------------------
264222
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
265223

0 commit comments

Comments
 (0)