Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list indentation #6408

Merged
merged 2 commits into from Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 10 additions & 15 deletions docs/usage/validators.md
Expand Up @@ -70,30 +70,25 @@ except ValidationError as e:
A few things to note on validators:

* validators are "class methods", so the first argument value they receive is the `UserModel` class, not an instance
of `UserModel`.
* the second argument is always the field value to validate; it can be named as you please
* you can also add any subset of the following arguments to the signature (the names **must** match):
* `values`: a dict containing the name-to-value mapping of any previously-validated fields
* `config`: the model config
* `field`: the field being validated. Type of object is `pydantic.fields.ModelField`.
* `**kwargs`: if provided, this will include the arguments above not explicitly listed in the signature
of `UserModel`.
* the second argument is the field value to validate; it can be named as you please
* the third argument is an instance of `pydantic.FieldValidationInfo`
* validators should either return the parsed value or raise a `ValueError` or `AssertionError`
(``assert`` statements may be used).
(``assert`` statements may be used).

!!! warning
If you make use of `assert` statements, keep in mind that running
Python with the [`-O` optimization flag](https://docs.python.org/3/using/cmdline.html#cmdoption-o)
disables `assert` statements, and **validators will stop working**.

* where validators rely on other values, you should be aware that:
* Validation is done in the order fields are defined.
E.g. in the example above, `password2` has access to `password1` (and `name`),
but `password1` does not have access to `password2`. See [Field Ordering](models.md#field-ordering)
for more information on how fields are ordered

* Validation is done in the order fields are defined.
E.g. in the example above, `password2` has access to `password1` (and `name`),
but `password1` does not have access to `password2`. See [Field Ordering](models.md#field-ordering)
for more information on how fields are ordered

* If validation fails on another field (or that field is missing) it will not be included in `values`, hence
`if 'password1' in values and ...` in this example.
* If validation fails on another field (or that field is missing) it will not be included in `values`, hence
`if 'password1' in values and ...` in this example.

## Annotated Validators

Expand Down