Parse a Python `timeout` argument into `Option >`: - `USE_CLIENT_DEFAULT_SENTINEL` string (not provided / explicit sentinel) → `None` (inherit client default) - Python `None` → `Some(None)` (disable timeout) - Python `float` → `Some(Some(Duration))` (specific timeout)
(
timeout: Option<Either<f64, &str>>,
)
| 16 | /// - Python `None` → `Some(None)` (disable timeout) |
| 17 | /// - Python `float` → `Some(Some(Duration))` (specific timeout) |
| 18 | pub(crate) fn parse_timeout( |
| 19 | timeout: Option<Either<f64, &str>>, |
| 20 | ) -> pyo3::PyResult<Option<Option<Duration>>> { |
| 21 | match timeout { |
| 22 | None => Ok(Some(None)), |
| 23 | Some(Left(secs)) => Ok(Some(Some(Duration::from_secs_f64(secs)))), |
| 24 | Some(Right(s)) => { |
| 25 | if s != USE_CLIENT_DEFAULT_SENTINEL { |
| 26 | Err(pyo3::exceptions::PyValueError::new_err(format!( |
| 27 | "Invalid timeout value: {s:?}" |
| 28 | ))) |
| 29 | } else { |
| 30 | Ok(None) |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | use pyo3::FromPyObject; |
| 37 |