-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Improve runtime errors for string constraints like pattern for incompatible types
#10158
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
Conversation
Deploying pydantic-docs with
|
| Latest commit: |
e16d6ee
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aaae9df8.pydantic-docs.pages.dev |
| Branch Preview URL: | https://more-verbose-error-annotatio.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10158 will not alter performanceComparing Summary
|
pattern for incompatible types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a clear improvement to me :)
| if 'type' in ve.errors()[0]['type']: | ||
| raise TypeError( | ||
| f"Unable to apply constraint '{constraint}' to supplied value {value} for schema of type '{schema_type}'" # noqa: B023 | ||
| ) | ||
| raise ve | ||
| return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an example here in a comment? It's not clear to me what the goal is just looking at hte code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for the tip!
Fix #10151
I suppose you could say this is contributing to #10036
Admittedly, this adds another custom wrap validator which is slower, but I think the behavior is better, and this is for a case that's already slow.