Fix validator_caller: run .validate() if overloaded, not if default
* Fix validator_caller: run .validate() if overloaded, not if default
* Unit test for IS_EMPTY_OR with custom validators that do not overload
.validate() (=backwards-compatibility check)
* validator_caller to support validation functions
(backwards-compatibility)
* Optimize
@@ -148,8 +148,9 @@ class Validator(object):
def validator_caller(func, value):
- if getattr(func, 'validate', None) is Validator.validate:
- return func.validate(value)
+ validate = getattr(func, 'validate', None)
+ if validate and validate is not Validator.validate:
+ return validate(value)
value, error = func(value)
if error is not None:
raise ValidationError(error)
