INNER CODE UNIT · Python

_dump

simonlin1212/Vibe-Research · calc/cli.py:303

def _dump(obj) -> str:
    try:
        return json.dumps(obj, ensure_ascii=False, indent=2, allow_nan=False)
    except ValueError:  # 输出树含 NaN/inf(理论上被 _res 守卫挡住;此处是最后一道闸):输出全新的干净信封,不复用原对象
        safe = {"calculation_id": None, "function": str((obj or {}).get("function")), "calc_version": CALC_VERSION,
                "inputs": None, "inputs_resolved": {}, "inputs_refs": [],
                "output": _error_out("输出含非有限数,已拦截;原始输入未回显", "nonfinite_output")}
        return json.dumps(safe, ensure_ascii=False, indent=2, allow_nan=False)


def main() -> None:
    # 🔴 **必须在打任何 JSON 之前**:中文 Windows 的管道默认 GBK,
    #    含 \xa0 会当场崩、其余中文会变成 Node 按 UTF-8 读不懂的字节(上游 issue #27)。
    force_utf8_stdio()
    p = argparse.ArgumentParser(description="确定性估值计算入口")
    p.add_argument("function", help="函数名,或 list 列出全部")
    p.add_argument("--args", default=None, help="JSON 对象字符串")
    p.add_argument("--args-file", default=None, help="含 JSON 对象的文件路径")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…