Keep source, config, and deploy files. Leave runtime data, uploads, and logs out of git. Co-authored-by: Cursor <cursoragent@cursor.com>
18 lines
502 B
Python
18 lines
502 B
Python
from __future__ import annotations
|
|
|
|
import math
|
|
from typing import Any
|
|
|
|
|
|
def json_safe(value: Any) -> Any:
|
|
"""Replace NaN and Infinity so Starlette can emit strict JSON."""
|
|
if isinstance(value, float):
|
|
if not math.isfinite(value):
|
|
return None
|
|
return value
|
|
if isinstance(value, dict):
|
|
return {key: json_safe(item) for key, item in value.items()}
|
|
if isinstance(value, (list, tuple)):
|
|
return [json_safe(item) for item in value]
|
|
return value
|