Add ascii_only option to StringConstraints#12907
Conversation
Merging this PR will improve performance by 5.19%
Performance Changes
Comparing |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
|
@davidolrik what do you think about this implementation, can you please review this PR ? Thank you |
Viicos
left a comment
There was a problem hiding this comment.
Please update the https://docs.pydantic.dev/latest/api/standard_library_types/#strings documentation to reflect the change.
ascii_only option to StringConstraints
I think you ment to highlight @davidhewitt and not me 😊 |
yeah, I wanted to highlight @davidhewitt. Sorry for the misunderstanding. |
|
@Viicos are there any more changes to be done ? |
feat: add ascii_only constraint to StringConstraints
Change Summary
Implements the
ascii_onlyoption forStringConstraintsas requested in #12300.Previously, developers had to use an unintuitive regex pattern to enforce ASCII-only strings:
This PR adds a clean boolean flag instead:
Changes made:
ascii_onlyfield toStrConstrainedValidator, implemented the check using Rust's native.is_ascii()before pattern matching for performance, and registered a newStringNotAsciierror typeascii_onlyparameter inStringConstraints, registered it in_known_annotated_metadata.py, and mapped it to the ASCII regex pattern in JSON Schema outputstring_not_asciisection tovalidation_errors.mdRelated issue number
Fixes #12300
Checklist
Selected Reviewer: @Viicos