Skip to content

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

Merged
merged 26 commits into from
Mar 17, 2023
Merged

Add field_name to ValidatorInfo #439

merged 26 commits into from
Mar 17, 2023

Conversation

adriangb
Copy link
Member

No description provided.

Copy link
Member

@samuelcolvin samuelcolvin left a 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-hq
Copy link

codspeed-hq bot commented Mar 14, 2023

CodSpeed Performance Report

Merging #439 field-in-validators (5eab2a7) will not alter performances.

Summary

🔥 0 improvements
❌ 0 regressions
✅ 93 untouched benchmarks

🆕 0 new benchmarks
⁉️ 0 dropped benchmarks

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2023

Codecov Report

Merging #439 (ca9b467) into main (cc79b05) will decrease coverage by 0.13%.
The diff coverage is 90.51%.

📣 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              
Impacted Files Coverage Δ
pydantic_core/core_schema.py 97.02% <83.09%> (-1.71%) ⬇️
src/validators/function.rs 99.06% <97.95%> (-0.37%) ⬇️
src/validators/generator.rs 91.90% <100.00%> (+0.04%) ⬆️
src/validators/mod.rs 98.74% <100.00%> (+<0.01%) ⬆️
src/validators/typed_dict.rs 98.29% <100.00%> (-0.66%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc79b05...ca9b467. Read the comment docs.

@adriangb adriangb marked this pull request as ready for review March 14, 2023 19:27
@adriangb adriangb self-assigned this Mar 15, 2023
@adriangb
Copy link
Member Author

please review

Copy link
Member

@samuelcolvin samuelcolvin left a 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.

schema: Required[CoreSchema]
ref: str
metadata: Any
serialization: SerSchema


def model_field_function_before_schema(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def model_field_function_before_schema(
def method_before_schema(
  1. fewer words
  2. should work for dataclasses too

Same below.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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 🤣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big rename in 3b91441

@adriangb adriangb changed the title Add field to ValidatorInfo Add field_name to ValidatorInfo Mar 16, 2023
@adriangb adriangb force-pushed the field-in-validators branch from 3b91441 to fd9030b Compare March 16, 2023 16:23
@adriangb adriangb force-pushed the field-in-validators branch from 5051b82 to ca9b467 Compare March 16, 2023 23:15
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.

4 participants