Skip to content

Commit

Permalink
Fix list indentation (#6408)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Jul 5, 2023
1 parent ac61c07 commit ca51901
Showing 1 changed file with 10 additions and 15 deletions.
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

0 comments on commit ca51901

Please sign in to comment.