Skip to content

Commit 068742e

Browse files
authored
fix error for long int input (#642)
1 parent 774fbbb commit 068742e

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/errors/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl ErrorType {
490490
Self::IntType => "Input should be a valid integer",
491491
Self::IntParsing => "Input should be a valid integer, unable to parse string as an integer",
492492
Self::IntFromFloat => "Input should be a valid integer, got a number with a fractional part",
493-
Self::IntParsingSize => "Unable to parse input string as an integer, exceed maximum size",
493+
Self::IntParsingSize => "Unable to parse input string as an integer, exceeded maximum size",
494494
Self::FloatType => "Input should be a valid number",
495495
Self::FloatParsing => "Input should be a valid number, unable to parse string as an number",
496496
Self::BytesType => "Input should be a valid bytes",

src/input/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn int_as_bool<'a>(input: &'a impl Input<'a>, int: i64) -> ValResult<'a, boo
5454
pub fn str_as_int<'s, 'l>(input: &'s impl Input<'s>, str: &'l str) -> ValResult<'s, EitherInt<'s>> {
5555
let len = str.len();
5656
if len > 4300 {
57-
Err(ValError::new(ErrorType::IntParsing, input))
57+
Err(ValError::new(ErrorType::IntParsingSize, input))
5858
} else if let Some(int) = _parse_str(input, str, len) {
5959
Ok(int)
6060
} else if let Some(str_stripped) = strip_decimal_zeros(str) {

tests/test_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def f(input_value, info):
224224
('bool_parsing', 'Input should be a valid boolean, unable to interpret input', None),
225225
('int_type', 'Input should be a valid integer', None),
226226
('int_parsing', 'Input should be a valid integer, unable to parse string as an integer', None),
227-
('int_parsing_size', 'Unable to parse input string as an integer, exceed maximum size', None),
227+
('int_parsing_size', 'Unable to parse input string as an integer, exceeded maximum size', None),
228228
('int_from_float', 'Input should be a valid integer, got a number with a fractional part', None),
229229
('multiple_of', 'Input should be a multiple of 42.1', {'multiple_of': 42.1}),
230230
('greater_than', 'Input should be greater than 42.1', {'gt': 42.1}),

tests/validators/test_int.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_negative_int(input_value, expected):
165165
(
166166
int(1e30),
167167
Err(
168-
'Unable to parse input string as an integer, exceed maximum size '
168+
'Unable to parse input string as an integer, exceeded maximum size '
169169
'[type=int_parsing_size, input_value=1e+30, input_type=float]'
170170
),
171171
),
@@ -197,7 +197,10 @@ def test_positive_json(input_value, expected):
197197
(0, Err('Input should be less than 0 [type=less_than, input_value=0, input_type=int]')),
198198
(-i64_max, -i64_max),
199199
(-i64_max - 1, -i64_max - 1),
200-
(-i64_max * 2, Err(' Unable to parse input string as an integer, exceed maximum size [type=int_parsing_size')),
200+
(
201+
-i64_max * 2,
202+
Err(' Unable to parse input string as an integer, exceeded maximum size [type=int_parsing_size'),
203+
),
201204
],
202205
)
203206
def test_negative_json(input_value, expected):
@@ -345,18 +348,18 @@ def test_too_long():
345348

346349
assert exc_info.value.errors(include_url=False) == [
347350
{
348-
'type': 'int_parsing',
351+
'type': 'int_parsing_size',
349352
'loc': (),
350-
'msg': 'Input should be a valid integer, unable to parse string as an integer',
353+
'msg': 'Unable to parse input string as an integer, exceeded maximum size',
351354
'input': '1' * 4301,
352355
}
353356
]
354357
# insert_assert(repr(exc_info.value))
355358
assert repr(exc_info.value) == (
356359
"1 validation error for int\n"
357-
" Input should be a valid integer, unable to parse string as an integer "
358-
"[type=int_parsing, input_value='111111111111111111111111...11111111111111111111111', input_type=str]\n"
359-
f" For further information visit https://errors.pydantic.dev/{__version__}/v/int_parsing"
360+
" Unable to parse input string as an integer, exceeded maximum size "
361+
"[type=int_parsing_size, input_value='111111111111111111111111...11111111111111111111111', input_type=str]\n"
362+
f" For further information visit https://errors.pydantic.dev/{__version__}/v/int_parsing_size"
360363
)
361364

362365

0 commit comments

Comments
 (0)