Skip to content

Support attrs validators#538

Merged
jcrist merged 1 commit intomainfrom
support-attrs-validators
Aug 26, 2023
Merged

Support attrs validators#538
jcrist merged 1 commit intomainfrom
support-attrs-validators

Conversation

@jcrist
Copy link
Copy Markdown
Owner

@jcrist jcrist commented Aug 26, 2023

This adds support for attrs validators. Validators are run after decoding the instance has completed, but before calling __attrs_post_init__. Since the builtin attrs validators include the attribute name in the error message, we don't add the field to the error path. This feels a bit weird, but is way easier since all of this can be done in pure python.

When possible, it'd be better to use msgspec's builtin constraints for handling validation. These will be much more performant, and integrate better with the rest of the system.

Fixes #535.

This adds support for attrs validators. Validators are run after
decoding the instance has completed, but before calling
`__attrs_post_init__`. Since the builtin attrs validators include the
attribute name in the error message, we don't add the field to the error
path. This feels *a bit* weird, but is way easier since all of this can
be done in pure python.

When possible, it'd be better to use msgspec's builtin constraints for
handling validation. These will be much more performant, and integrate
better with the rest of the system.
@jcrist jcrist merged commit d40bc43 into main Aug 26, 2023
@jcrist jcrist deleted the support-attrs-validators branch August 26, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for attrs field(validators=...)

1 participant