pydantic / pydantic-core

Core validation logic for pydantic written in rust
MIT License
1.4k stars 232 forks source link

Support `BigInt` serialization for `int` subclasses #1417

Closed kxx317 closed 1 month ago

kxx317 commented 1 month ago

Change Summary

Modified the infer.rs infer_to_python_known function to support the inference of BigInt/int beyond the i64 limit for IntSubclass object type when SerMode=Json.

My approach is similar to code inside return_enums.extract_bound. I attempted to import that function into infer.rs and re-use it but couldn't get it working so I duplicated the if logics instead (first time to rust). As this was my first time working with Rust, I’m uncertain whether re-using it is the best solution especially since it doesn’t seem to align precisely with the purpose of return_enums.extract_bound.

Related issue number

fix https://github.com/pydantic/pydantic/issues/10152

Checklist

Selected Reviewer: @sydney-runkle

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.30%. Comparing base (ab503cb) to head (725d640). Report is 157 commits behind head on main.

Files Patch % Lines
src/serializers/infer.rs 80.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1417 +/- ## ========================================== - Coverage 90.21% 89.30% -0.92% ========================================== Files 106 112 +6 Lines 16339 17701 +1362 Branches 36 41 +5 ========================================== + Hits 14740 15807 +1067 - Misses 1592 1874 +282 - Partials 7 20 +13 ``` | [Files](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic) | Coverage Δ | | |---|---|---| | [src/serializers/infer.rs](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417?src=pr&el=tree&filepath=src%2Fserializers%2Finfer.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic#diff-c3JjL3NlcmlhbGl6ZXJzL2luZmVyLnJz) | `90.98% <80.00%> (-4.14%)` | :arrow_down: | ... and [48 files with indirect coverage changes](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic). Last update [f4a0675...725d640](https://app.codecov.io/gh/pydantic/pydantic-core/pull/1417?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic).
codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #1417 will not alter performance

Comparing kxx317:custom-int-type-infer-bigint-error (725d640) with main (f4a0675)

Summary

✅ 155 untouched benchmarks

kxx317 commented 1 month ago

please review