Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions tests/validators/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ..conftest import Err, PyAndJson, plain_repr

i64_max = 9_223_372_036_854_775_807
f64_max = 1.7976931348623157e308


Expand All @@ -20,6 +21,7 @@
(0, 0),
(1, 1),
(42, 42),
(i64_max + 1, i64_max + 1),
('42', 42),
(' 42.1 ', 42.1),
('42.123', 42.123),
Expand Down
Loading