MCPcopy Create free account
hub / github.com/apify/impit / parse_timeout

Function parse_timeout

impit-python/src/request.rs:18–34  ·  view source on GitHub ↗

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>>,
)

Source from the content-addressed store, hash-verified

16/// - Python `None` → `Some(None)` (disable timeout)
17/// - Python `float` → `Some(Some(Duration))` (specific timeout)
18pub(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
36use pyo3::FromPyObject;
37

Callers 4

newMethod · 0.85
requestMethod · 0.85
newMethod · 0.85
requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…