@@ -70,6 +70,18 @@ def __init__(self, message, cause=None, context=()):
70
70
self .instance = None
71
71
self .schema = None
72
72
73
+ @classmethod
74
+ def create_from (cls , other ):
75
+ new_error = cls (other .message , other .cause , other .context )
76
+ new_error .path = other .path
77
+ new_error .schema_path = other .schema_path
78
+ new_error ._details_set = other ._details_set
79
+ new_error .validator_keyword = other .validator_keyword
80
+ new_error .validator_value = other .validator_value
81
+ new_error .instance = other .instance
82
+ new_error .schema = other .schema
83
+ return new_error
84
+
73
85
@property
74
86
def validator (self ):
75
87
warnings .warn (
@@ -112,22 +124,8 @@ def __unicode__(self):
112
124
__str__ = __unicode__
113
125
114
126
115
- class ValidationError (_Error ):
116
- def to_schema_error (self ):
117
- schema_error = SchemaError (self .message )
118
- schema_error .path = self .path
119
- schema_error .schema_path = self .schema_path
120
- schema_error .context = self .context
121
- schema_error .cause = self .cause
122
- schema_error ._details_set = self ._details_set
123
- schema_error .validator_keyword = self .validator_keyword
124
- schema_error .validator_value = self .validator_value
125
- schema_error .instance = self .instance
126
- schema_error .schema = self .schema
127
- return schema_error
128
-
129
-
130
127
class SchemaError (_Error ): pass
128
+ class ValidationError (_Error ): pass
131
129
class RefResolutionError (Exception ): pass
132
130
class UnknownType (Exception ): pass
133
131
@@ -236,7 +234,7 @@ def is_valid(self, instance, _schema=None):
236
234
@classmethod
237
235
def check_schema (cls , schema ):
238
236
for error in cls (cls .META_SCHEMA ).iter_errors (schema ):
239
- raise error . to_schema_error ( )
237
+ raise SchemaError . create_from ( error )
240
238
241
239
def iter_errors (self , instance , _schema = None ):
242
240
if _schema is None :
0 commit comments