@@ -113,9 +113,7 @@ impl UnionValidator {
113
113
let strict = state. strict_or ( self . strict ) ;
114
114
let mut errors = MaybeErrors :: new ( self . custom_error . as_ref ( ) ) ;
115
115
116
- // we use this to track the validation against the most compatible union member
117
- // up to the current point
118
- let mut success: Option < ( Py < PyAny > , Exactness , Option < usize > ) > = None ;
116
+ let mut best_match: Option < ( Py < PyAny > , Exactness , Option < usize > ) > = None ;
119
117
120
118
for ( choice, label) in & self . choices {
121
119
let state = & mut state. rebind_extra ( |extra| {
@@ -151,7 +149,7 @@ impl UnionValidator {
151
149
// if the fields_set_count is not available for either the current best match or the new candidate,
152
150
// we use the exactness to determine the best match.
153
151
let new_success_is_best_match: bool =
154
- success
152
+ best_match
155
153
. as_ref ( )
156
154
. map_or ( true , |( _, cur_exactness, cur_fields_set_count) | {
157
155
match ( * cur_fields_set_count, new_fields_set_count) {
@@ -161,13 +159,13 @@ impl UnionValidator {
161
159
} ) ;
162
160
163
161
if new_success_is_best_match {
164
- success = Some ( ( new_success, new_exactness, new_fields_set_count) ) ;
162
+ best_match = Some ( ( new_success, new_exactness, new_fields_set_count) ) ;
165
163
}
166
164
}
167
165
} ,
168
166
Err ( ValError :: LineErrors ( lines) ) => {
169
167
// if we don't yet know this validation will succeed, record the error
170
- if success . is_none ( ) {
168
+ if best_match . is_none ( ) {
171
169
errors. push ( choice, label. as_deref ( ) , lines) ;
172
170
}
173
171
}
@@ -179,12 +177,12 @@ impl UnionValidator {
179
177
state. exactness = old_exactness;
180
178
state. fields_set_count = old_fields_set_count;
181
179
182
- if let Some ( ( success , exactness, fields_set_count) ) = success {
180
+ if let Some ( ( best_match , exactness, fields_set_count) ) = best_match {
183
181
state. floor_exactness ( exactness) ;
184
182
if let Some ( count) = fields_set_count {
185
183
state. add_fields_set ( count) ;
186
184
}
187
- return Ok ( success ) ;
185
+ return Ok ( best_match ) ;
188
186
}
189
187
190
188
// no matches, build errors
0 commit comments