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

Fix list indentation #6408

merged 2 commits into from Jul 5, 2023

Conversation

ofek
Copy link
Contributor

@ofek ofek commented Jul 4, 2023

Screenshot 2023-07-03 230701

Selected Reviewer: @lig

@lig
Copy link
Contributor

lig commented Jul 4, 2023

@lig lig requested a review from tpdorsey July 4, 2023 17:22
@lig lig self-assigned this Jul 4, 2023
@tpdorsey
Copy link
Contributor

tpdorsey commented Jul 4, 2023

The approach is correct, but it should be 4 spaces per indent, including an additional indent on wrapping lines.

* 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
* validators should either return the parsed value or raise a `ValueError` or `AssertionError`
    (``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

    * 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.

The difference in rendering is down to different markdown parsing engines. The mkdocs parser is more strict about indents.

@ofek
Copy link
Contributor Author

ofek commented Jul 4, 2023

Where do you see those rules?

@tpdorsey
Copy link
Contributor

tpdorsey commented Jul 5, 2023

@ofek https://www.markdownguide.org/basic-syntax#adding-elements-in-lists

@ofek
Copy link
Contributor Author

ofek commented Jul 5, 2023

I increased the indentation and also updated the text to reflect the actual state of v2

@tpdorsey
Copy link
Contributor

tpdorsey commented Jul 5, 2023

Thank you for the contribution!

@tpdorsey tpdorsey merged commit ca51901 into pydantic:main Jul 5, 2023
49 checks passed
@ofek ofek deleted the patch-1 branch July 5, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants