Skip to content

Commit 57f2948

Browse files
committed
Handle the TypeVar for format checker callables.
Mostly follows sphinx-doc/sphinx#10785
1 parent ea1c71a commit 57f2948

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/api/jsonschema/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ Package summary
1717
.. automodule:: jsonschema
1818
:members:
1919
:imported-members:
20+
21+
22+
.. autodata:: jsonschema._format._F

docs/conf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@
3636

3737
html_theme = "furo"
3838

39+
# See sphinx-doc/sphinx#10785
40+
_TYPE_ALIASES = {
41+
"jsonschema._format._F", # format checkers
42+
}
43+
44+
45+
def _resolve_type_aliases(app, env, node, contnode):
46+
if (
47+
node["refdomain"] == "py"
48+
and node["reftype"] == "class"
49+
and node["reftarget"] in _TYPE_ALIASES
50+
):
51+
return app.env.get_domain("py").resolve_xref(
52+
env,
53+
node["refdoc"],
54+
app.builder,
55+
"data",
56+
node["reftarget"],
57+
node,
58+
contnode,
59+
)
60+
61+
62+
def setup(app):
63+
app.connect("missing-reference", _resolve_type_aliases)
64+
65+
3966
# = Builders =
4067

4168
doctest_global_setup = """

jsonschema/_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from jsonschema.exceptions import FormatError
1212

1313
_FormatCheckCallable = typing.Callable[[object], bool]
14+
#: A format checker callable.
1415
_F = typing.TypeVar("_F", bound=_FormatCheckCallable)
1516
_RaisesType = typing.Union[
1617
typing.Type[Exception], typing.Tuple[typing.Type[Exception], ...],

0 commit comments

Comments
 (0)