-
Notifications
You must be signed in to change notification settings - Fork 291
Add field_name
to ValidatorInfo
#439
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
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 this looks good.
Nice that we can reuse the extra.field
element which is otherwise used for validating assignment. Can we think of any scenario where those two might conflict? I don't think so, but worth thinking about.
Definitely worth adding a unit test for this with validate assignment.
CodSpeed Performance ReportMerging #439 Summary
|
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #439 +/- ##
==========================================
- Coverage 95.49% 95.36% -0.13%
==========================================
Files 93 93
Lines 11144 11119 -25
Branches 10 22 +12
==========================================
- Hits 10642 10604 -38
- Misses 497 510 +13
Partials 5 5
Continue to review full report in Codecov by Sentry.
|
please review |
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 this is looking good.
pydantic_core/core_schema.py
Outdated
schema: Required[CoreSchema] | ||
ref: str | ||
metadata: Any | ||
serialization: SerSchema | ||
|
||
|
||
def model_field_function_before_schema( |
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.
def model_field_function_before_schema( | |
def method_before_schema( |
- fewer words
- should work for dataclasses too
Same below.
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.
Is method
/function
really the right distinction (I realize I was the one that introduced it). Consider:
class Model:
@validator
def val_x(cls, val, info): val
This is technically a bound class method or a method bound to the class. But we'd be putting it down the function
code path. Which is a bit confusing. In general I think the nomenclature of function
vs. method
in Python is confusing. So I think perhaps it's best to differentiate between a validator attached to a model field vs. not. And by model
here I mean model
in the broadest sense to include dataclasses, TypedDict, etc. So maybe something like field_before_validation_callback
and before_validation_callback
would be good names?
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.
then I would have field_before_validation_callback
and general_before_validation_callback
.
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.
That is fine by me, let's confirm on call before I rename for the 5th time 🤣
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.
Big rename in 3b91441
3b91441
to
fd9030b
Compare
5051b82
to
ca9b467
Compare
No description provided.