|
23 | 23 | except ImportError: |
24 | 24 | from funcsigs import signature, Signature |
25 | 25 |
|
26 | | -from makefun import with_signature, wraps |
| 26 | +from makefun import wraps |
27 | 27 |
|
28 | 28 | from valid8.utils.decoration_tools import apply_on_each_func_args_sig |
29 | 29 | from valid8.utils.typing_tools import is_pep484_nonable |
@@ -93,25 +93,11 @@ def get_variable_str(self): |
93 | 93 | return self.validator.validated_field_name + '=' + str(self.var_value) |
94 | 94 |
|
95 | 95 |
|
96 | | -# Python 3+: load the 'more explicit api' |
97 | | -if use_typing: |
98 | | - new_sig = """(self, |
99 | | - validated_func: Callable, |
100 | | - *validation_func: ValidationFuncs, |
101 | | - error_type: 'Type[ValidationError]' = None, |
102 | | - help_msg: str = None, |
103 | | - none_policy: int = None, |
104 | | - **kw_context_args):""" |
105 | | -else: |
106 | | - new_sig = None |
107 | | - |
108 | | - |
109 | 96 | class FuncValidator(Validator): |
110 | 97 | """ |
111 | 98 | Represents a special kind of `Validator` responsible to validate a function input or output |
112 | 99 | """ |
113 | 100 |
|
114 | | - @with_signature(new_sig) |
115 | 101 | def __init__(self, |
116 | 102 | validated_func, # type: Callable |
117 | 103 | *validation_func, # type: ValidationFuncs |
@@ -162,7 +148,6 @@ class InputValidator(FuncValidator): |
162 | 148 | Represents a special kind of `Validator` responsible to validate a function input. |
163 | 149 | """ |
164 | 150 |
|
165 | | - @with_signature(new_sig) |
166 | 151 | def __init__(self, |
167 | 152 | validated_func, # type: Callable, |
168 | 153 | *validation_func, # type: ValidationFuncs |
@@ -203,7 +188,6 @@ def __init__(self, |
203 | 188 | class OutputValidator(FuncValidator): |
204 | 189 | """ Represents a special kind of `Validator` responsible to validate a function output. """ |
205 | 190 |
|
206 | | - @with_signature(new_sig) |
207 | 191 | def __init__(self, |
208 | 192 | validated_func, # type: Callable |
209 | 193 | *validation_func, # type: ValidationFuncs |
@@ -260,27 +244,12 @@ def assert_valid(self, |
260 | 244 | **kw_context_args) |
261 | 245 |
|
262 | 246 |
|
263 | | -# Python 3+: load the 'more explicit api' |
264 | | -if use_typing: |
265 | | - new_sig = """(self, |
266 | | - validated_class: Callable, |
267 | | - validated_field_name: str, |
268 | | - *validation_func: ValidationFuncs, |
269 | | - error_type: 'Type[ClassFieldValidationError]' = None, |
270 | | - help_msg: str = None, |
271 | | - none_policy: int = None, |
272 | | - **kw_context_args):""" |
273 | | -else: |
274 | | - new_sig = None |
275 | | - |
276 | | - |
277 | 247 | class ClassFieldValidator(Validator): |
278 | 248 | """ |
279 | 249 | Represents a special kind of `Validator` responsible to validate a class field. |
280 | 250 | As opposed to other validators, the name of the field is hardcoded. |
281 | 251 | """ |
282 | 252 |
|
283 | | - @with_signature(new_sig) |
284 | 253 | def __init__(self, |
285 | 254 | validated_class, # type: Callable, |
286 | 255 | validated_field_name, # type: str |
@@ -341,21 +310,7 @@ def get_validated_class_display_name(self): |
341 | 310 | return self.validated_class.__name__ |
342 | 311 |
|
343 | 312 |
|
344 | | -# Python 3+: load the 'more explicit api' |
345 | | -if use_typing: |
346 | | - new_sig = """(cls, |
347 | | - field_name, |
348 | | - *validation_func: ValidationFuncs, |
349 | | - help_msg: str = None, |
350 | | - error_type: 'Type[InputValidationError]' = None, |
351 | | - none_policy: int = None, |
352 | | - **kw_context_args) -> 'Type':""" |
353 | | -else: |
354 | | - new_sig = None |
355 | | - |
356 | | - |
357 | 313 | @class_decorator(flat_mode_decorated_name='cls') |
358 | | -@with_signature(new_sig) |
359 | 314 | def validate_field(cls, |
360 | 315 | field_name, |
361 | 316 | *validation_func, # type: ValidationFuncs |
@@ -439,21 +394,7 @@ def myfunc(a, b): |
439 | 394 | return decorate_several_with_validation(f, none_policy=none_policy, _out_=_out_, **kw_validation_funcs) |
440 | 395 |
|
441 | 396 |
|
442 | | -# Python 3+: load the 'more explicit api' |
443 | | -if use_typing: |
444 | | - new_sig = """(f, |
445 | | - arg_name, |
446 | | - *validation_func: ValidationFuncs, |
447 | | - help_msg: str = None, |
448 | | - error_type: 'Type[InputValidationError]' = None, |
449 | | - none_policy: int = None, |
450 | | - **kw_context_args) -> Callable:""" |
451 | | -else: |
452 | | - new_sig = None |
453 | | - |
454 | | - |
455 | 397 | @function_decorator(flat_mode_decorated_name='f') |
456 | | -@with_signature(new_sig) |
457 | 398 | def validate_arg(f, |
458 | 399 | arg_name, |
459 | 400 | *validation_func, # type: ValidationFuncs |
@@ -485,18 +426,6 @@ def validate_arg(f, |
485 | 426 | return decorate_with_validation(f, arg_name, *validation_func, **kwargs) |
486 | 427 |
|
487 | 428 |
|
488 | | -# Python 3+: load the 'more explicit api' |
489 | | -if use_typing: |
490 | | - new_sig = """(*validation_func: ValidationFuncs, |
491 | | - help_msg: str = None, |
492 | | - error_type: 'Type[OutputValidationError]' = None, |
493 | | - none_policy: int = None, |
494 | | - **kw_context_args) -> Callable:""" |
495 | | -else: |
496 | | - new_sig = None |
497 | | - |
498 | | - |
499 | | -@with_signature(new_sig) |
500 | 429 | def validate_out(*validation_func, # type: ValidationFuncs |
501 | 430 | **kwargs): |
502 | 431 | # type: (...) -> Callable |
@@ -530,20 +459,6 @@ def decorate(f): |
530 | 459 | """ The reserved key for output validation """ |
531 | 460 |
|
532 | 461 |
|
533 | | -# Python 3+: load the 'more explicit api' |
534 | | -if use_typing: |
535 | | - new_sig = """(cls, |
536 | | - field_name: str, |
537 | | - *validation_func: ValidationFuncs, |
538 | | - help_msg: str = None, |
539 | | - error_type: 'Union[Type[InputValidationError], Type[OutputValidationError]]' = None, |
540 | | - none_policy: int = None, |
541 | | - **kw_context_args) -> Callable:""" |
542 | | -else: |
543 | | - new_sig = None |
544 | | - |
545 | | - |
546 | | -@with_signature(new_sig) |
547 | 462 | def decorate_cls_with_validation(cls, |
548 | 463 | field_name, # type: str |
549 | 464 | *validation_func, # type: ValidationFuncs |
@@ -721,21 +636,6 @@ def decorate_several_with_validation(func, |
721 | 636 | return func |
722 | 637 |
|
723 | 638 |
|
724 | | -# Python 3+: load the 'more explicit api' |
725 | | -if use_typing: |
726 | | - new_sig = """(func, |
727 | | - arg_name: str, |
728 | | - *validation_func: ValidationFuncs, |
729 | | - help_msg: str = None, |
730 | | - error_type: 'Union[Type[InputValidationError], Type[OutputValidationError]]' = None, |
731 | | - none_policy: int = None, |
732 | | - _constructor_of_cls_: 'Type'=None, |
733 | | - **kw_context_args) -> Callable:""" |
734 | | -else: |
735 | | - new_sig = None |
736 | | - |
737 | | - |
738 | | -@with_signature(new_sig) |
739 | 639 | def decorate_with_validation(func, |
740 | 640 | arg_name, # type: str |
741 | 641 | *validation_func, # type: ValidationFuncs |
@@ -826,23 +726,6 @@ class fields)""" |
826 | 726 | pass |
827 | 727 |
|
828 | 728 |
|
829 | | -# Python 3+: load the 'more explicit api' |
830 | | -if use_typing: |
831 | | - new_sig = """(validated_func: Callable, |
832 | | - s: Signature, |
833 | | - arg_name: str, |
834 | | - *validation_func: ValidationFuncs, |
835 | | - help_msg: str = None, |
836 | | - error_type: 'Type[InputValidationError]' = None, |
837 | | - none_policy: int = None, |
838 | | - validated_class: 'Type'=None, |
839 | | - validated_class_field_name: str=None, |
840 | | - **kw_context_args):""" |
841 | | -else: |
842 | | - new_sig = None |
843 | | - |
844 | | - |
845 | | -@with_signature(new_sig) |
846 | 729 | def _create_function_validator(validated_func, # type: Callable |
847 | 730 | s, # type: Signature |
848 | 731 | arg_name, # type: str |
@@ -895,10 +778,11 @@ def _create_function_validator(validated_func, # type: Callable |
895 | 778 | error_type=error_type, help_msg=help_msg, **kw_context_args) |
896 | 779 |
|
897 | 780 |
|
898 | | -def decorate_with_validators(func, |
| 781 | +def decorate_with_validators(func, # type: Callable |
899 | 782 | func_signature=None, # type: Signature |
900 | 783 | **validators # type: Union[Validator, List[Validator]] |
901 | 784 | ): |
| 785 | + # type: (...) -> Callable |
902 | 786 | """ |
903 | 787 | Utility method to decorate the provided function with the provided input and output Validator objects. Since this |
904 | 788 | method takes Validator objects as argument, it is for advanced users. |
|
0 commit comments