Skip to content

Commit 17384e7

Browse files
committed
Fix sphinx nitpick error arising from annotations
Type annotations can use variable names in order to support easily named constructs (e.g. `FooType = Union[int, str]; x: FooType`). However, such variable names are then seen by sphinx autodoc, which does not evaluate them. As a result, for such a name to avoid tripping nitpick warnings, these names need to be resolvable. The simplest resolution is to remove the use of any internal variables for this purpose (at least where they would be seen by sphinx), and use the longhand description of types in such cases.
1 parent 631fba1 commit 17384e7

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

jsonschema/_types.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@
88

99
from jsonschema.exceptions import UndefinedTypeCheck
1010

11-
# internal type declarations for annotations
12-
_TypeCheckerFunc = typing.Callable[["TypeChecker", typing.Any], bool]
13-
_TypeCheckerMapping = typing.Mapping[str, _TypeCheckerFunc]
14-
1511

1612
# unfortunately, the type of pmap is generic, and if used as the attr.ib
1713
# converter, the generic type is presented to mypy, which then fails to match
1814
# the concrete type of a type checker mapping
1915
# this "do nothing" wrapper presents the correct information to mypy
2016
def _typed_pmap_converter(
21-
init_val: _TypeCheckerMapping,
22-
) -> _TypeCheckerMapping:
23-
return typing.cast(_TypeCheckerMapping, pmap(init_val))
17+
init_val: typing.Mapping[
18+
str,
19+
typing.Callable[["TypeChecker", typing.Any], bool],
20+
],
21+
) -> typing.Mapping[str, typing.Callable[["TypeChecker", typing.Any], bool]]:
22+
return typing.cast(
23+
typing.Mapping[
24+
str,
25+
typing.Callable[["TypeChecker", typing.Any], bool],
26+
],
27+
pmap(init_val),
28+
)
2429

2530

2631
def is_array(checker, instance):
@@ -78,8 +83,11 @@ class TypeChecker(object):
7883
The initial mapping of types to their checking functions.
7984
"""
8085

81-
_type_checkers: _TypeCheckerMapping = attr.ib(
82-
default=pmap(), converter=_typed_pmap_converter,
86+
_type_checkers: typing.Mapping[
87+
str, typing.Callable[["TypeChecker", typing.Any], bool],
88+
] = attr.ib(
89+
default=pmap(),
90+
converter=_typed_pmap_converter,
8391
)
8492

8593
def is_type(self, instance, type):

0 commit comments

Comments
 (0)