Skip to content

Commit

Permalink
Docs: Fixing constr argument regex -> pattern // Typo (#6452)
Browse files Browse the repository at this point in the history
  • Loading branch information
miili authored Jul 5, 2023
1 parent ca51901 commit 88f2810
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/6452-miili.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Docs: Fixed `constr` documentation, renamed old `regex` to new `pattern`.
2 changes: 1 addition & 1 deletion docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ Pydantic V1 used Python's regex library. Pydantic V2 uses the Rust [regex crate]
This crate is not just a "Rust version of regular expressions", it's a completely different approach to regular expressions.
In particular, it promises linear time searching of strings in exchange for dropping a couple of features (namely look arounds and backreferences).
We believe this is a tradeoff worth making, in particular because Pydantic is used to validate untrusted input where ensuring things don't accidentally run in exponential time depending on the untrusted input is important.
One the flipside, for anyone not using these features complex regex validation should be orders of magnitude faster because it's done in Rust and in linear time.
On the flipside, for anyone not using these features complex regex validation should be orders of magnitude faster because it's done in Rust and in linear time.
If you need those regex features you can create a custom validator that does the regex validation in Python:

```py
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/schema_mappings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ additional = ""
defined_in = "JSON Schema Core"
notes = "If the type has values declared for the constraints, they are included as validations. See the mapping for `constr` below."

["constr(regex='^text$', min_length=2, max_length=10)"]
py_type = "constr(regex='^text$', min_length=2, max_length=10)"
["constr(pattern='^text$', min_length=2, max_length=10)"]
py_type = "constr(pattern='^text$', min_length=2, max_length=10)"
json_type = "string"
defined_in = "JSON Schema Validation"
notes = "Any argument not passed to the function (not defined) will not be included in the schema."
Expand Down
3 changes: 1 addition & 2 deletions docs/usage/types/string_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ The following arguments are available when using the `constr` type function
- `strict: bool = False`: controls type coercion
- `min_length: int = None`: minimum length of the string
- `max_length: int = None`: maximum length of the string
- `curtail_length: int = None`: shrinks the string length to the set value when it is longer than the set value
- `regex: str = None`: regex to validate the string against
- `pattern: str = None`: regex to validate the string against

0 comments on commit 88f2810

Please sign in to comment.