Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
46 changes: 43 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pydantic-core"
version = "2.18.3"
version = "2.18.4"
edition = "2021"
license = "MIT"
homepage = "https://github.com/pydantic/pydantic-core"
Expand Down Expand Up @@ -44,7 +44,7 @@ base64 = "0.21.7"
num-bigint = "0.4.4"
python3-dll-a = "0.2.7"
uuid = "1.8.0"
jiter = { version = "0.2.1", features = ["python"] }
jiter = { version = "0.4.1", features = ["python"] }

[lib]
name = "_pydantic_core"
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate core;

use std::sync::OnceLock;

use jiter::StringCacheMode;
use jiter::{map_json_error, PartialMode, PythonParse, StringCacheMode};
use pyo3::exceptions::PyTypeError;
use pyo3::{prelude::*, sync::GILOnceCell};

Expand Down Expand Up @@ -63,8 +63,21 @@ pub fn from_json<'py>(
CacheStringsArg::Bool(b) => b.into(),
CacheStringsArg::Literal(mode) => mode,
};
jiter::python_parse(py, json_bytes, allow_inf_nan, cache_mode, allow_partial)
.map_err(|e| jiter::map_json_error(json_bytes, &e))
let partial_mode = if allow_partial {
PartialMode::On
} else {
PartialMode::Off
};
let parse_builder = PythonParse {
allow_inf_nan,
cache_mode,
partial_mode,
catch_duplicate_keys: false,
lossless_floats: false,
};
parse_builder
.python_parse(py, json_bytes)
.map_err(|e| map_json_error(json_bytes, &e))
}

pub fn get_pydantic_core_version() -> &'static str {
Expand Down
14 changes: 11 additions & 3 deletions src/validators/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::PyDict;

use jiter::JsonValue;
use jiter::{JsonValue, PartialMode, PythonParse};

use crate::errors::{ErrorType, ErrorTypeDefaults, ValError, ValLineError, ValResult};
use crate::input::{EitherBytes, Input, InputType, ValidationMatch};
Expand Down Expand Up @@ -64,8 +64,16 @@ impl Validator for JsonValidator {
validator.validate(py, &json_value, &mut json_state)
}
None => {
let obj = jiter::python_parse(py, json_bytes, true, state.cache_str(), false)
.map_err(|e| map_json_err(input, e, json_bytes))?;
let parse_builder = PythonParse {
allow_inf_nan: true,
cache_mode: state.cache_str(),
partial_mode: PartialMode::Off,
catch_duplicate_keys: false,
lossless_floats: false,
};
let obj = parse_builder
.python_parse(py, json_bytes)
.map_err(|e| map_json_err(json_bytes, &e))?;
Ok(obj.unbind())
}
}
Expand Down