Keep non-object tool arguments invalid under Python optimization

Closed
AR
2mo ago
+22-1

Under python -O, the existing assert in BaseToolCallPart.args_as_dict() is removed, allowing parsed non-object JSON to flow through as a dictionary. Make the check explicit so optimized and normal interpreters preserve the same invalid-argument behavior.

  • No issue required: this is an obvious one-line runtime correctness fix.

Tests

  • uv run pytest tests/test_messages.py::test_args_as_dict_raise_if_invalid_non_dict_json tests/test_messages.py::test_args_as_dict_rejects_non_dict_json_under_optimization (2 passed)

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (Not applicable.)
  • PR title is fit for the release changelog.