mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
tweaking exception definitions
This commit is contained in:
@@ -53,3 +53,11 @@ class ValidationError(ValueError):
|
||||
|
||||
class ConfigError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
class Missing(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class Extra(ValueError):
|
||||
pass
|
||||
|
||||
+2
-9
@@ -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)
|
||||
|
||||
@@ -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]),
|
||||
|
||||
Reference in New Issue
Block a user