Skip to content

Commit

Permalink
Uprev jiter to v0.4.1 and pydantic-core to v2.18.4 (#1306)
Browse files Browse the repository at this point in the history
Co-authored-by: David Hewitt <[email protected]>
  • Loading branch information
sydney-runkle and davidhewitt authored Jun 3, 2024
1 parent 81e3bd3 commit 37ad925
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
python-version: ${{ matrix.python-version }}

- run: pip install -r tests/requirements.txt
# TODO: remove this after the the next release of typing-extensions (v4.12.3 or v.4.13.0)
- run: pip uninstall -y typing-extensions
- run: pip install -U git+https://github.com/python/typing_extensions@main

- run: pip install -e .
env:
Expand Down
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
12 changes: 10 additions & 2 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,7 +64,15 @@ 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)
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(input, e, json_bytes))?;
Ok(obj.unbind())
}
Expand Down

0 comments on commit 37ad925

Please sign in to comment.