diff options
author | Stephen Rosen <sirosen@globus.org> | 2022-01-05 23:21:06 +0000 |
---|---|---|
committer | Stephen Rosen <sirosen@globus.org> | 2022-01-05 23:42:25 +0000 |
commit | 17384e735ca7411c0199cd39f3375e0b25a8ca81 (patch) | |
tree | 7a9c1499bf27ca867d4f1d12d566cd8170050782 /jsonschema/_types.py | |
parent | 631fba10862dca89f032231e1aba70225379f314 (diff) | |
download | jsonschema-17384e735ca7411c0199cd39f3375e0b25a8ca81.tar.gz |
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.
Diffstat (limited to 'jsonschema/_types.py')
-rw-r--r-- | jsonschema/_types.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/jsonschema/_types.py b/jsonschema/_types.py index d0525bd..9d59eb3 100644 --- a/jsonschema/_types.py +++ b/jsonschema/_types.py @@ -8,19 +8,24 @@ import attr from jsonschema.exceptions import UndefinedTypeCheck -# internal type declarations for annotations -_TypeCheckerFunc = typing.Callable[["TypeChecker", typing.Any], bool] -_TypeCheckerMapping = typing.Mapping[str, _TypeCheckerFunc] - # unfortunately, the type of pmap is generic, and if used as the attr.ib # converter, the generic type is presented to mypy, which then fails to match # the concrete type of a type checker mapping # this "do nothing" wrapper presents the correct information to mypy def _typed_pmap_converter( - init_val: _TypeCheckerMapping, -) -> _TypeCheckerMapping: - return typing.cast(_TypeCheckerMapping, pmap(init_val)) + init_val: typing.Mapping[ + str, + typing.Callable[["TypeChecker", typing.Any], bool], + ], +) -> typing.Mapping[str, typing.Callable[["TypeChecker", typing.Any], bool]]: + return typing.cast( + typing.Mapping[ + str, + typing.Callable[["TypeChecker", typing.Any], bool], + ], + pmap(init_val), + ) def is_array(checker, instance): @@ -78,8 +83,11 @@ class TypeChecker(object): The initial mapping of types to their checking functions. """ - _type_checkers: _TypeCheckerMapping = attr.ib( - default=pmap(), converter=_typed_pmap_converter, + _type_checkers: typing.Mapping[ + str, typing.Callable[["TypeChecker", typing.Any], bool], + ] = attr.ib( + default=pmap(), + converter=_typed_pmap_converter, ) def is_type(self, instance, type): |