@@ -4,6 +4,7 @@ extern crate core;
44
55use std:: sync:: OnceLock ;
66
7+ use jiter:: StringCacheMode ;
78use pyo3:: exceptions:: PyTypeError ;
89use pyo3:: { prelude:: * , sync:: GILOnceCell } ;
910
@@ -38,19 +39,31 @@ pub use validators::{validate_core_schema, PySome, SchemaValidator};
3839
3940use crate :: input:: Input ;
4041
41- #[ pyfunction( signature = ( data, * , allow_inf_nan=true , cache_strings=true ) ) ]
42+ #[ derive( FromPyObject ) ]
43+ pub enum CacheStringsArg {
44+ Bool ( bool ) ,
45+ Literal ( StringCacheMode ) ,
46+ }
47+
48+ #[ pyfunction( signature = ( data, * , allow_inf_nan=true , cache_strings=CacheStringsArg :: Bool ( true ) , allow_partial=false ) ) ]
4249pub fn from_json < ' py > (
4350 py : Python < ' py > ,
4451 data : & Bound < ' _ , PyAny > ,
4552 allow_inf_nan : bool ,
46- cache_strings : bool ,
53+ cache_strings : CacheStringsArg ,
54+ allow_partial : bool ,
4755) -> PyResult < Bound < ' py , PyAny > > {
4856 let v_match = data
4957 . validate_bytes ( false )
5058 . map_err ( |_| PyTypeError :: new_err ( "Expected bytes, bytearray or str" ) ) ?;
5159 let json_either_bytes = v_match. into_inner ( ) ;
5260 let json_bytes = json_either_bytes. as_slice ( ) ;
53- jiter:: python_parse ( py, json_bytes, allow_inf_nan, cache_strings) . map_err ( |e| jiter:: map_json_error ( json_bytes, & e) )
61+ let cache_mode = match cache_strings {
62+ CacheStringsArg :: Bool ( b) => b. into ( ) ,
63+ CacheStringsArg :: Literal ( mode) => mode,
64+ } ;
65+ jiter:: python_parse ( py, json_bytes, allow_inf_nan, cache_mode, allow_partial)
66+ . map_err ( |e| jiter:: map_json_error ( json_bytes, & e) )
5467}
5568
5669pub fn get_pydantic_core_version ( ) -> & ' static str {
0 commit comments