MCPcopy Create free account
hub / github.com/apify/crawlee-python / _timedelta_from_secs

Function _timedelta_from_secs

src/crawlee/_utils/models.py:49–64  ·  view source on GitHub ↗
(
    value: float | timedelta | Any | None,
    handler: Callable[[Any], timedelta],
)

Source from the content-addressed store, hash-verified

47
48
49def _timedelta_from_secs(
50 value: float | timedelta | Any | None,
51 handler: Callable[[Any], timedelta],
52) -> timedelta | None:
53 if value == float('inf'):
54 return timedelta.max
55
56 # If the value is a string-encoded number, decode it
57 if isinstance(value, str):
58 with suppress(ValidationError):
59 value = _number_parser.validate_python(value)
60
61 if not isinstance(value, (int, float)):
62 return handler(value)
63
64 return timedelta(seconds=value)
65
66
67timedelta_ms = Annotated[timedelta, PlainSerializer(_timedelta_to_ms), WrapValidator(_timedelta_from_ms)]

Callers

nothing calls this directly

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected