Skip to content
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

Add fail-fast for dicts, model and dataclass #1543

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

uriyyo
Copy link
Contributor

@uriyyo uriyyo commented Nov 17, 2024

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 this pydantic-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
Contributor Author

uriyyo commented Nov 17, 2024

please review

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.60%. Comparing base (ab503cb) to head (5dd9abd).
Report is 230 commits behind head on main.

Files with missing lines Patch % Lines
src/validators/dict.rs 87.50% 1 Missing ⚠️
src/validators/typed_dict.rs 88.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    17931    +1592     
  Branches       36       40       +4     
==========================================
+ Hits        14740    16067    +1327     
- Misses       1592     1844     +252     
- Partials        7       20      +13     
Files with missing lines Coverage Δ
python/pydantic_core/core_schema.py 94.86% <100.00%> (+0.10%) ⬆️
src/validators/dataclass.rs 89.31% <100.00%> (-9.07%) ⬇️
src/validators/model_fields.rs 95.18% <100.00%> (-1.29%) ⬇️
src/validators/dict.rs 96.84% <87.50%> (-0.04%) ⬇️
src/validators/typed_dict.rs 89.66% <88.88%> (-2.39%) ⬇️

... and 49 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 by Codecov. Last update 6472887...5dd9abd. Read the comment docs.

Copy link

codspeed-hq bot commented Nov 17, 2024

CodSpeed Performance Report

Merging #1543 will not alter performance

Comparing uriyyo:more-fail-fast (5dd9abd) with main (6472887)

Summary

✅ 155 untouched benchmarks

@uriyyo
Copy link
Contributor Author

uriyyo commented Nov 17, 2024

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:

struct ValidationContext {
    fail_fast: bool,
    errors: Vec<ValLineError>,
}

impl ValidationContext {
    fn new(fail_fast: bool) -> Self {
        Self {
            fail_fast,
            errors: Vec::new(),
        }
    }

    fn default() -> Self {
        return Self::new(false);
    }

    fn should_stop(self) -> bool {
        self.fail_fast && self.has_errors()
    }

    fn has_errors(self) -> bool {
        !self.errors.is_empty()
    }

    fn add_error(mut self, error: ValLineError) {
        self.errors.push(error);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants