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 proper underscore handling to float and complex types. #5356

Merged
merged 10 commits into from
Jul 28, 2024
Prev Previous commit
Next Next commit
remove all earlier changes in complex.rs and float.rs
  • Loading branch information
dannasman committed Jul 23, 2024
commit a41fb5ecfa6096576937711a06ed910fe2d43aff
2 changes: 1 addition & 1 deletion vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ fn parse_str(s: &str) -> Option<Complex64> {
let value = match s.strip_suffix(|c| c == 'j' || c == 'J') {
None => {
Complex64::new(crate::literal::float::parse_str(s)?, 0.0)
}
},
Some(mut s) => {
let mut real = 0.0;
// Find the central +/- operator. If it exists, parse the real part.
Expand Down
8 changes: 5 additions & 3 deletions vm/src/builtins/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ fn float_from_string(val: PyObjectRef, vm: &VirtualMachine) -> PyResult<f64> {
)));
};

crate::literal::float::parse_bytes(b).ok_or(val.repr(vm)
.map(|repr| vm.new_value_error(format!("could not convert string to float: {repr}")))
.unwrap_or_else(|e| e))
crate::literal::float::parse_bytes(b).ok_or_else(|| {
val.repr(vm)
.map(|repr| vm.new_value_error(format!("could not convert string to float: {repr}")))
.unwrap_or_else(|e| e)
})
}

#[pyclass(
Expand Down
Loading