@@ -72,10 +72,11 @@ def __init__(
72
72
73
73
@classmethod
74
74
def check_schema (cls , schema ):
75
- for error in cls (cls .META_SCHEMA ).iter_errors (schema ):
75
+ for error in list (cls (cls .META_SCHEMA ).iter_errors (
76
+ schema , _first_only = True )):
76
77
raise SchemaError .create_from (error )
77
78
78
- def iter_errors (self , instance , _schema = None ):
79
+ def iter_errors (self , instance , _schema = None , _first_only = False ):
79
80
if _schema is None :
80
81
_schema = self .schema
81
82
@@ -104,6 +105,9 @@ def iter_errors(self, instance, _schema=None):
104
105
error .schema_path .appendleft (k )
105
106
yield error
106
107
108
+ if _first_only :
109
+ return
110
+
107
111
def descend (self , instance , schema , path = None , schema_path = None ):
108
112
for error in self .iter_errors (instance , schema ):
109
113
if path is not None :
@@ -113,7 +117,8 @@ def descend(self, instance, schema, path=None, schema_path=None):
113
117
yield error
114
118
115
119
def validate (self , * args , ** kwargs ):
116
- for error in self .iter_errors (* args , ** kwargs ):
120
+ kwargs ['_first_only' ] = True
121
+ for error in list (self .iter_errors (* args , ** kwargs )):
117
122
raise error
118
123
119
124
def is_type (self , instance , type ):
@@ -132,8 +137,8 @@ def is_type(self, instance, type):
132
137
return isinstance (instance , pytypes )
133
138
134
139
def is_valid (self , instance , _schema = None ):
135
- error = next (self .iter_errors (instance , _schema ), None )
136
- return error is None
140
+ errors = list (self .iter_errors (instance , _schema , _first_only = True ) )
141
+ return not len ( errors )
137
142
138
143
if version is not None :
139
144
Validator = validates (version )(Validator )
0 commit comments