|
8 | 8 |
|
9 | 9 | from jsonschema.exceptions import UndefinedTypeCheck
|
10 | 10 |
|
11 |
| -# internal type declarations for annotations |
12 |
| -_TypeCheckerFunc = typing.Callable[["TypeChecker", typing.Any], bool] |
13 |
| -_TypeCheckerMapping = typing.Mapping[str, _TypeCheckerFunc] |
14 |
| - |
15 | 11 |
|
16 | 12 | # unfortunately, the type of pmap is generic, and if used as the attr.ib
|
17 | 13 | # converter, the generic type is presented to mypy, which then fails to match
|
18 | 14 | # the concrete type of a type checker mapping
|
19 | 15 | # this "do nothing" wrapper presents the correct information to mypy
|
20 | 16 | 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 | + ) |
24 | 29 |
|
25 | 30 |
|
26 | 31 | def is_array(checker, instance):
|
@@ -78,8 +83,11 @@ class TypeChecker(object):
|
78 | 83 | The initial mapping of types to their checking functions.
|
79 | 84 | """
|
80 | 85 |
|
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, |
83 | 91 | )
|
84 | 92 |
|
85 | 93 | def is_type(self, instance, type):
|
|
0 commit comments