Skip to content

Commit 01aabef

Browse files
committed
support trailing strings
1 parent cc2c46c commit 01aabef

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

python/pydantic_core/_pydantic_core.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def from_json(
395395
*,
396396
allow_inf_nan: bool = True,
397397
cache_strings: bool | Literal['all', 'keys', 'none'] = True,
398-
allow_partial: bool = False,
398+
allow_partial: bool | Literal[ "off", "on", "trailing-strings"] = False,
399399
) -> Any:
400400
"""
401401
Deserialize JSON data to a Python object.

src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ pub enum CacheStringsArg {
4848
Literal(StringCacheMode),
4949
}
5050

51-
#[pyfunction(signature = (data, *, allow_inf_nan=true, cache_strings=CacheStringsArg::Bool(true), allow_partial=false))]
51+
#[pyfunction(signature = (data, *, allow_inf_nan=true, cache_strings=CacheStringsArg::Bool(true), allow_partial=PartialMode::Off))]
5252
pub fn from_json<'py>(
5353
py: Python<'py>,
5454
data: &Bound<'_, PyAny>,
5555
allow_inf_nan: bool,
5656
cache_strings: CacheStringsArg,
57-
allow_partial: bool,
57+
allow_partial: PartialMode,
5858
) -> PyResult<Bound<'py, PyAny>> {
5959
let v_match = data
6060
.validate_bytes(false, ValBytesMode { ser: BytesMode::Utf8 })
@@ -65,15 +65,10 @@ pub fn from_json<'py>(
6565
CacheStringsArg::Bool(b) => b.into(),
6666
CacheStringsArg::Literal(mode) => mode,
6767
};
68-
let partial_mode = if allow_partial {
69-
PartialMode::On
70-
} else {
71-
PartialMode::Off
72-
};
7368
let parse_builder = PythonParse {
7469
allow_inf_nan,
7570
cache_mode,
76-
partial_mode,
71+
partial_mode: allow_partial,
7772
catch_duplicate_keys: false,
7873
lossless_floats: false,
7974
};

0 commit comments

Comments
 (0)