-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Allow arbitrary types in model #209
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
Allow arbitrary types in model #209
Conversation
Codecov Report
@@ Coverage Diff @@
## master #209 +/- ##
==========================================
+ Coverage 99.84% 99.84% +<.01%
==========================================
Files 11 11
Lines 1285 1300 +15
Branches 235 237 +2
==========================================
+ Hits 1283 1298 +15
Misses 2 2 |
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.
Otherwise, I think looks good.
pydantic/validators.py
Outdated
| if arbitrary_types_allowed: | ||
| return [make_arbitrary_type_validator(type_)] | ||
| else: | ||
| raise errors.ConfigError(f'no validator found for {type_}') |
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 should be a RuntimeError, it's not a config problem and will happen at runtime.
|
|
||
| with pytest.raises(ValidationError) as exc_info: | ||
| ArbitraryTypeAllowedModel(t=C()) | ||
| assert exc_info.value.errors() == [ |
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.
can you please test your changes with exc_info.value.json()? I don't think that ctx with type is JSON serializable. To my mind we need to use utils.display_as_type when we firing ArbitraryTypeError exception.
| @@ -204,3 +204,10 @@ class UUIDVersionError(PydanticValueError): | |||
|
|
|||
| def __init__(self, *, required_version: int) -> None: | |||
| super().__init__(required_version=required_version) | |||
|
|
|||
|
|
|||
| class ArbitraryTypeError(PydanticTypeError): | |||
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.
I think for better readability we need to define code = 'type_error.arbitrary_type' or rename class to ArbitraryError
* Allow functions within model_class validators * make fields_set flexible * improve coverage * fix error message test to support pypy
Implements #182