Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ url = "2.5.4"
idna = "1.0.3"
base64 = "0.22.1"
num-bigint = "0.4.6"
num-traits = "0.2.19"
uuid = "1.16.0"
jiter = { version = "0.9.0", features = ["python"] }
hex = "0.4.3"
Expand Down
4 changes: 4 additions & 0 deletions src/input/input_json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;

use jiter::{JsonArray, JsonObject, JsonValue};
use num_traits::cast::ToPrimitive;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList, PyString};
use speedate::MicrosecondsPrecisionOverflowBehavior;
Expand Down Expand Up @@ -173,6 +174,9 @@ impl<'py, 'data> Input<'py> for JsonValue<'data> {
match self {
JsonValue::Float(f) => Ok(ValidationMatch::exact(EitherFloat::F64(*f))),
JsonValue::Int(i) => Ok(ValidationMatch::strict(EitherFloat::F64(*i as f64))),
JsonValue::BigInt(b) => Ok(ValidationMatch::strict(EitherFloat::F64(
b.to_f64().expect("BigInt should always return some value"),
))),
JsonValue::Bool(b) if !strict => Ok(ValidationMatch::lax(EitherFloat::F64(if *b { 1.0 } else { 0.0 }))),
JsonValue::Str(str) if !strict => str_as_float(self, str).map(ValidationMatch::lax),
_ => Err(ValError::new(ErrorTypeDefaults::FloatType, self)),
Expand Down
6 changes: 5 additions & 1 deletion tests/validators/test_float.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import re
import sys
from decimal import Decimal
from typing import Any

Expand All @@ -11,7 +12,8 @@

from ..conftest import Err, PyAndJson, plain_repr

f64_max = 1.7976931348623157e308
i64_max = (2**63) - 1
f64_max = sys.float_info.max


@pytest.mark.parametrize(
Expand All @@ -20,6 +22,8 @@
(0, 0),
(1, 1),
(42, 42),
(i64_max + 1, i64_max + 1),
(f64_max, f64_max),
('42', 42),
(' 42.1 ', 42.1),
('42.123', 42.123),
Expand Down
2 changes: 1 addition & 1 deletion tests/validators/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ..conftest import Err, PyAndJson, plain_repr

i64_max = 9_223_372_036_854_775_807
i64_max = (2**63) - 1


@pytest.mark.parametrize(
Expand Down
Loading