tweaking exception definitions

This commit is contained in:
Samuel Colvin
2017-05-08 17:33:37 +01:00
parent 11ea624e62
commit d52cf17f15
3 changed files with 11 additions and 10 deletions
+8
View File
@@ -53,3 +53,11 @@ class ValidationError(ValueError):
class ConfigError(RuntimeError):
pass
class Missing(ValueError):
pass
class Extra(ValueError):
pass
+2 -9
View File
@@ -1,7 +1,7 @@
from collections import OrderedDict
from types import FunctionType
from .exceptions import Error, ValidationError
from .exceptions import Error, Extra, Missing, ValidationError
from .fields import Field
from .validators import dict_validator
@@ -14,6 +14,7 @@ class BaseConfig:
raise_exception = True
validate_all = False
ignore_extra = True
# TODO allow extra
def inherit_config(self_config, parent_config) -> BaseConfig:
@@ -63,14 +64,6 @@ class MetaModel(type):
return super().__new__(mcs, name, bases, namespace)
class Missing(ValueError):
pass
class Extra(ValueError):
pass
MISSING = Missing('field required')
MISSING_ERROR = Error(MISSING, None, None, None)
EXTRA_ERROR = Error(Extra('extra fields not permitted'), None, None, None)
+1 -1
View File
@@ -81,7 +81,7 @@ def enum_validator(v, field, **kwargs) -> Enum:
return field.type_(v)
# order is important here, for example: bool is a subclass of int, datetime is a subclass of date
# order is important here, for example: bool is a subclass of int so has to come first, datetime before date same
_VALIDATORS = [
(str, [not_none_validator, str_validator, anystr_length_validator]),
(bytes, [not_none_validator, bytes_validator, anystr_length_validator]),