|
4 | 4 | import sys |
5 | 5 | from collections import OrderedDict |
6 | 6 |
|
7 | | -from makefun import with_signature |
8 | | - |
9 | 7 | from valid8 import Validator, failure_raiser, ValidationError, ValidationFailure |
10 | 8 | from valid8.base import getfullargspec as v8_getfullargspec, get_callable_name, is_mini_lambda |
11 | 9 | from valid8.common_syntax import FunctionDefinitionError, make_validation_func_callables |
|
16 | 14 |
|
17 | 15 | try: # python 3.5+ |
18 | 16 | # noinspection PyUnresolvedReferences |
19 | | - from typing import Callable, Type, Any, TypeVar, Union, Iterable, Tuple, Mapping, Optional |
| 17 | + from typing import Callable, Type, Any, TypeVar, Union, Iterable, Tuple, Mapping, Optional, Dict |
20 | 18 | from valid8.common_syntax import ValidationFuncs |
21 | 19 | use_type_hints = sys.version_info > (3, 0) |
22 | 20 | except ImportError: |
|
65 | 63 | Validators = OneOrSeveralVFDefinitions |
66 | 64 |
|
67 | 65 |
|
68 | | -# Python 3+: load the 'more explicit api' |
69 | | -if use_type_hints: |
70 | | - new_sig = """(self, |
71 | | - validated_field: 'DescriptorField', |
72 | | - *validation_func: ValidationFuncs, |
73 | | - error_type: 'Type[ValidationError]' = None, |
74 | | - help_msg: str = None, |
75 | | - none_policy: int = None, |
76 | | - **kw_context_args):""" |
77 | | -else: |
78 | | - new_sig = None |
79 | | - |
80 | | - |
81 | 66 | class FieldValidator(Validator): |
82 | 67 | """ |
83 | 68 | Represents a `Validator` responsible to validate a `field` |
84 | 69 | """ |
85 | 70 | __slots__ = '__weakref__', 'validated_field', 'base_validation_funcs' |
86 | 71 |
|
87 | | - @with_signature(new_sig) |
88 | 72 | def __init__(self, |
89 | 73 | validated_field, # type: 'DescriptorField' |
90 | | - validators, |
| 74 | + validators, # type: Validators |
91 | 75 | **kwargs |
92 | 76 | ): |
93 | 77 | """ |
@@ -210,11 +194,13 @@ def new_validation_callable(val, **ctx): |
210 | 194 | return make_validator_callable |
211 | 195 |
|
212 | 196 | def get_additional_info_for_repr(self): |
| 197 | + # type: (...) -> str |
213 | 198 | return 'validated_field=%s' % self.validated_field.qualname |
214 | 199 |
|
215 | 200 | def _get_name_for_errors(self, |
216 | 201 | name # type: str |
217 | 202 | ): |
| 203 | + # type: (...) -> str |
218 | 204 | """ override this so that qualname is only called if an error is raised, not before """ |
219 | 205 | return self.validated_field.qualname |
220 | 206 |
|
|
0 commit comments