@@ -11,11 +11,11 @@ use ahash::AHashMap;
11
11
12
12
use crate :: build_tools:: { py_schema_err, py_schema_error_type} ;
13
13
use crate :: errors:: { ErrorType , ValError , ValResult } ;
14
- use crate :: input:: { decimal_as_int , EitherInt , Input , ValidationMatch } ;
14
+ use crate :: input:: { Input , ValidationMatch } ;
15
15
use crate :: py_gc:: PyGcTraverse ;
16
16
use crate :: tools:: SchemaDict ;
17
17
18
- use super :: decimal:: get_decimal_type ;
18
+ use super :: decimal:: try_from_decimal_to_int ;
19
19
use super :: { BuildValidator , CombinedValidator , DefinitionsBuilder , ValidationState , Validator } ;
20
20
21
21
#[ derive( Debug , Clone , Default ) ]
@@ -126,8 +126,11 @@ impl<T: Debug> LiteralLookup<T> {
126
126
}
127
127
}
128
128
// if the input is a Decimal type, we need to check if its value is in the expected_ints
129
- if let Ok ( Some ( v) ) = self . try_from_dec_to_int ( py, input, expected_ints) {
130
- return Ok ( Some ( v) ) ;
129
+ if let Ok ( Some ( value) ) = try_from_decimal_to_int ( py, input) {
130
+ let Some ( id) = expected_ints. get ( & value) else {
131
+ return Ok ( None ) ;
132
+ } ;
133
+ return Ok ( Some ( ( input, & self . values [ * id] ) ) ) ;
131
134
}
132
135
}
133
136
@@ -150,9 +153,12 @@ impl<T: Debug> LiteralLookup<T> {
150
153
}
151
154
}
152
155
if !strict {
153
- // if the input is a Decimal type, we need to check if its value is in the expected_strings
154
- if let Ok ( Some ( v) ) = self . try_from_dec_to_str ( py, input, expected_strings) {
155
- return Ok ( Some ( v) ) ;
156
+ // if the input is a Decimal type, we need to check if its value is in the expected_ints
157
+ if let Ok ( Some ( value) ) = try_from_decimal_to_int ( py, input) {
158
+ let Some ( id) = expected_strings. get ( & value. to_string ( ) ) else {
159
+ return Ok ( None ) ;
160
+ } ;
161
+ return Ok ( Some ( ( input, & self . values [ * id] ) ) ) ;
156
162
}
157
163
}
158
164
}
@@ -180,65 +186,6 @@ impl<T: Debug> LiteralLookup<T> {
180
186
Ok ( None )
181
187
}
182
188
183
- fn try_from_dec_to_int < ' a , ' py , I : Input < ' py > + ?Sized > (
184
- & self ,
185
- py : Python < ' py > ,
186
- input : & ' a I ,
187
- expected_ints : & AHashMap < i64 , usize > ,
188
- ) -> ValResult < Option < ( & ' a I , & T ) > > {
189
- let Some ( py_input) = input. as_python ( ) else {
190
- return Ok ( None ) ;
191
- } ;
192
-
193
- if let Ok ( false ) = py_input. is_instance ( get_decimal_type ( py) ) {
194
- return Ok ( None ) ;
195
- }
196
-
197
- let Ok ( EitherInt :: Py ( dec_value) ) = decimal_as_int ( input, py_input) else {
198
- return Ok ( None ) ;
199
- } ;
200
-
201
- let Ok ( either_int) = dec_value. exact_int ( ) else {
202
- return Ok ( None ) ;
203
- } ;
204
- let int = either_int. into_i64 ( py) ?;
205
-
206
- let Some ( id) = expected_ints. get ( & int) else {
207
- return Ok ( None ) ;
208
- } ;
209
-
210
- Ok ( Some ( ( input, & self . values [ * id] ) ) )
211
- }
212
-
213
- fn try_from_dec_to_str < ' a , ' py , I : Input < ' py > + ?Sized > (
214
- & self ,
215
- py : Python < ' py > ,
216
- input : & ' a I ,
217
- expected_strings : & AHashMap < String , usize > ,
218
- ) -> ValResult < Option < ( & ' a I , & T ) > > {
219
- let Some ( py_input) = input. as_python ( ) else {
220
- return Ok ( None ) ;
221
- } ;
222
-
223
- if let Ok ( false ) = py_input. is_instance ( get_decimal_type ( py) ) {
224
- return Ok ( None ) ;
225
- }
226
-
227
- let Ok ( EitherInt :: Py ( dec_value) ) = decimal_as_int ( input, py_input) else {
228
- return Ok ( None ) ;
229
- } ;
230
-
231
- let Ok ( either_int) = dec_value. exact_int ( ) else {
232
- return Ok ( None ) ;
233
- } ;
234
- let int = either_int. into_i64 ( py) ?;
235
- if let Some ( id) = expected_strings. get ( & int. to_string ( ) ) {
236
- return Ok ( Some ( ( input, & self . values [ * id] ) ) ) ;
237
- }
238
-
239
- Ok ( None )
240
- }
241
-
242
189
/// Used by int enums
243
190
pub fn validate_int < ' a , ' py , I : Input < ' py > + ?Sized > (
244
191
& self ,
0 commit comments