Open lud4ik opened 5 years ago
U can redefine base clases.
class MyBool(t.Bool):
def check_value(self, value):
if not isinstance(value, bool):
self._failure("My custom error", value=value)
MyBool().check(True)
or user t.Call
def not_some_validator(value):
if value == "some":
return t.DataError('My custom error.')
return value
t.Call(not_some_validator).check("some")
I'm not sure what is the best way but it's not look like "kostyls"
I need some time to figure out proper way.
а можна ли разширить так чтобы все текста ошибок можна было переопределять? к примеру если t.Int(gt=0) при 0 задать "Please enter non-zero value"
можно, на выходных постараюсь сделать
Привет, это еще актуально? Тоже интересует ..
In version2 DataError has code
field and to_struct
method that returns code
as well as message. It can be used with any localisation library. I think this should solve localisation problem.
I have a scheme of t.Dict with several fields. I want when required field is absent to replace default error string. What is the best way to do it? without kostyls...