Skip to content

Commit

Permalink
respect config["cache_strings"] in the json validator
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Mar 26, 2024
1 parent af431b4 commit 42a9f2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python/pydantic_core/core_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class CoreConfig(TypedDict, total=False):
Requires exceptiongroup backport pre Python 3.11.
coerce_numbers_to_str: Whether to enable coercion of any `Number` type to `str` (not applicable in `strict` mode).
regex_engine: The regex engine to use for regex pattern validation. Default is 'rust-regex'. See `StringSchema`.
cache_strings: Whether to cache strings. Default is `True`, `True` or `'all'` is required to cache strings
during general validation since validators don't know if they're in a key or a value.
"""

title: str
Expand Down Expand Up @@ -110,6 +112,7 @@ class CoreConfig(TypedDict, total=False):
validation_error_cause: bool # default: False
coerce_numbers_to_str: bool # default: False
regex_engine: Literal['rust-regex', 'python-re'] # default: 'rust-regex'
cache_strings: bool | Literal['all', 'keys', 'none'] # default: 'True'


IncExCall: TypeAlias = 'set[int | str] | dict[int | str, IncExCall] | None'
Expand Down
2 changes: 1 addition & 1 deletion src/validators/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Validator for JsonValidator {
validator.validate(py, &json_value, &mut json_state)
}
None => {
let obj = jiter::python_parse(py, json_bytes, true, true.into(), false)
let obj = jiter::python_parse(py, json_bytes, true, state.cache_str(), false)
.map_err(|e| map_json_err(input, e, json_bytes))?;
Ok(obj.unbind())
}
Expand Down

0 comments on commit 42a9f2f

Please sign in to comment.