-
Notifications
You must be signed in to change notification settings - Fork 292
Add eitherfloat #691
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 eitherfloat #691
Conversation
85cdccc
to
cf833be
Compare
cf833be
to
ca38362
Compare
please review |
CodSpeed Performance ReportMerging #691 Summary
Benchmarks breakdown
|
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #691 +/- ##
==========================================
- Coverage 93.72% 93.69% -0.03%
==========================================
Files 99 99
Lines 13802 13822 +20
Branches 25 25
==========================================
+ Hits 12936 12951 +15
- Misses 860 865 +5
Partials 6 6
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
@adriangb or @samuelcolvin I think one of you should look at this before we merge but looks okay to me.
Also, we'll need to update the pydantic docs in a separate PR to cover this new error code.
Co-authored-by: David Montague <[email protected]>
565a9db
to
3180d8d
Compare
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 looking good.
Please update.
pydantic_core/core_schema.py
Outdated
@@ -3802,6 +3802,7 @@ def definition_reference_schema( | |||
'int_from_float', | |||
'float_type', | |||
'float_parsing', | |||
'float_parsing_size', |
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.
do we have a test which actually raises this error?
If it's not possible to actually made it happen, or very rare, I think we just use float_parsing
.
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.
I didn't manage to test it. I replaced it with float_parsing
src/input/input_python.rs
Outdated
@@ -302,35 +302,40 @@ impl<'a> Input<'a> for PyAny { | |||
} | |||
} | |||
|
|||
fn ultra_strict_float(&self) -> ValResult<f64> { | |||
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>> { | |||
if self.is_instance_of::<PyInt>() { | |||
Err(ValError::new(ErrorType::FloatType, self)) | |||
} else if let Ok(float) = self.extract::<f64>() { |
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.
we shouldn't use extract here, but rather is_instance_of
, then use EitherFloat::Py
.
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.
Done, thanks
@@ -302,35 +302,40 @@ impl<'a> Input<'a> for PyAny { | |||
} | |||
} | |||
|
|||
fn ultra_strict_float(&self) -> ValResult<f64> { | |||
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>> { |
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.
I think with this change we might be able to remove ultra_strict_float
completely, maybe that's too much work for this PR.
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.
If I remove the functionultra_strict_float
, do I have to change the behavior of strict_float
and lax_float
?
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.
leave it for now.
please review |
Change Summary
Add Eitherfloat
Related issue number
fix #639
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @dmontagu