Skip to content

Commit 313d092

Browse files
Jacob Zhongclaude
andcommitted
python: handle FpError::ZivRetryLimitExceeded in the bindings
The new float error variant (a Ziv loop that exhausts its retry budget, only reachable if a radius bound is wrong) was missing from the two FpResult→PyResult matches, so the python crate failed to compile since 50e7b3d. It now raises RuntimeError (not a user-facing Python error, but a "please report this" case). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 335a74a commit 313d092

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎python/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Fix
6+
- The bindings now handle `dashu-float`'s new `FpError::ZivRetryLimitExceeded` (a Ziv loop that
7+
exhausts its retry budget — only possible if a radius bound is wrong) — it raises `RuntimeError`
8+
instead of failing to compile on a non-exhaustive match.
9+
510
## 0.6.0
611

712
### Add

‎python/src/cache.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::cell::RefCell;
1515

1616
use dashu::base::Sign;
1717
use dashu::float::{ConstCache, Context, FBig, FpError, FpResult, Repr, Word, round::Round};
18-
use pyo3::exceptions::{PyValueError, PyZeroDivisionError};
18+
use pyo3::exceptions::{PyRuntimeError, PyValueError, PyZeroDivisionError};
1919
use pyo3::prelude::*;
2020

2121
thread_local! {
@@ -61,6 +61,12 @@ pub fn unwrap_float<R: Round, const B: Word>(
6161
Err(FpError::Indeterminate) => {
6262
Err(PyZeroDivisionError::new_err("indeterminate form (0/0)"))
6363
}
64+
Err(FpError::ZivRetryLimitExceeded) => Err(PyRuntimeError::new_err(
65+
"the Ziv retry limit was exceeded; the result is not correctly rounded (please report this case to the maintainer)",
66+
)),
67+
Err(FpError::ZivRetryLimitExceeded) => Err(PyRuntimeError::new_err(
68+
"the Ziv retry limit was exceeded; the result is not correctly rounded (please report this case to the maintainer)",
69+
)),
6470
}
6571
}
6672

@@ -88,6 +94,12 @@ pub fn unwrap_complex<R: Round, const B: Word>(
8894
Err(FpError::Indeterminate) => {
8995
Err(PyZeroDivisionError::new_err("indeterminate form (0/0)"))
9096
}
97+
Err(FpError::ZivRetryLimitExceeded) => Err(PyRuntimeError::new_err(
98+
"the Ziv retry limit was exceeded; the result is not correctly rounded (please report this case to the maintainer)",
99+
)),
100+
Err(FpError::ZivRetryLimitExceeded) => Err(PyRuntimeError::new_err(
101+
"the Ziv retry limit was exceeded; the result is not correctly rounded (please report this case to the maintainer)",
102+
)),
91103
}
92104
}
93105

0 commit comments

Comments
 (0)