Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add fail-fast for dicts#1543

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
uriyyo wants to merge4 commits intopydantic:main
base:main
Choose a base branch
Loading
fromuriyyo:more-fail-fast
Open

Conversation

uriyyo
Copy link
Contributor

@uriyyouriyyo commentedNov 17, 2024
edited
Loading

Change Summary

Add fail-fast feature to:

  • dict
  • typed-dict
  • dataclass-arguments
  • model-fields

Related issue number

#1345

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with thispydantic-core (except for expected changes)
  • My PR is ready to review,please add a comment including the phrase "please review" to assign reviewers

@uriyyo
Copy link
ContributorAuthor

please review

pydantic-hooky[bot] reacted with thumbs up emoji

@codecovCodecov
Copy link

codecovbot commentedNov 17, 2024
edited
Loading

Codecov Report

Attention: Patch coverage is90.00000% with2 lines in your changes missing coverage. Please review.

Project coverage is 89.60%. Comparing base(ab503cb) to head(805c64a).
Report is 264 commits behind head on main.

Files with missing linesPatch %Lines
src/validators/dict.rs87.50%1 Missing⚠️
src/validators/typed_dict.rs88.88%1 Missing⚠️
Additional details and impacted files
@@            Coverage Diff             @@##             main    #1543      +/-   ##==========================================- Coverage   90.21%   89.60%   -0.61%==========================================  Files         106      112       +6       Lines       16339    17867    +1528       Branches       36       40       +4     ==========================================+ Hits        14740    16010    +1270- Misses       1592     1837     +245- Partials        7       20      +13
Files with missing linesCoverage Δ
python/pydantic_core/core_schema.py94.88% <100.00%> (+0.11%)⬆️
src/validators/dict.rs96.84% <87.50%> (-0.04%)⬇️
src/validators/typed_dict.rs89.66% <88.88%> (-2.39%)⬇️

... and60 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update562fad3...805c64a. Read thecomment docs.

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedNov 17, 2024
edited
Loading

CodSpeed Performance Report

Merging#1543 willnot alter performance

Comparinguriyyo:more-fail-fast (805c64a) withmain (562fad3)

Summary

✅ 157 untouched benchmarks

@uriyyo
Copy link
ContributorAuthor

After implementing this feature I thought maybe it's make sense to add kinda validation context structure to not duplicate fail-fast check logic, it can look like this:

structValidationContext{fail_fast:bool,errors:Vec<ValLineError>,}implValidationContext{fnnew(fail_fast:bool) ->Self{Self{            fail_fast,errors:Vec::new(),}}fndefault() ->Self{returnSelf::new(false);}fnshould_stop(self) ->bool{self.fail_fast &&self.has_errors()}fnhas_errors(self) ->bool{        !self.errors.is_empty()}fnadd_error(mutself,error:ValLineError){self.errors.push(error);}}

Copy link
Contributor

@davidhewittdavidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, overall the implementation seems fine.

RE your refactoring idea, I was beginning to think of something similar recently, see#1517, probably this solves related problems.

I realise that looking at this, I'm a bit unsure what the user-facing result is. What order do they expect validation of fields to be in? Does it matter if we validate the first field but not the last N, because the second was fail fast? What if the next time we randomly did these in a different order, and the performance was different? Maybe there were even side effects 👀

Under what cases is fail-fast useful for a model?

I would love to understand some more about this. I think if it's about making errors shorter, we could make it easier to see just the first error. If it's about performance, well, maybe we just make validation faster so that fail-fast doesn't matter.

Unlike lists and sequences, with potentially large inputs, a model should have a relatively small finite number of fields, so I don't know how much performance is gained by failing early...

uriyyo reacted with thumbs up emoji
@uriyyo
Copy link
ContributorAuthor

@davidhewitt Your points totally makes sense to me. I removed fail-fast for model and dataclass and left it for dict and typed-dict.

@uriyyouriyyo changed the titleAdd fail-fast for dicts, model and dataclassAdd fail-fast for dictsDec 26, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@davidhewittdavidhewittAwaiting requested review from davidhewitt

Assignees

@davidhewittdavidhewitt

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@uriyyo@davidhewitt

[8]ページ先頭

©2009-2025 Movatter.jp