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

Support attrs validators #538

Merged
merged 1 commit into from
Aug 26, 2023
Merged

Support attrs validators #538

merged 1 commit into from
Aug 26, 2023

Conversation

jcrist
Copy link
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
7 checks passed
@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