From 6d2806f10c59df6753a23000709ad807ba62aca1 Mon Sep 17 00:00:00 2001 From: Rohan Mehta Date: Mon, 16 Jun 2025 10:50:20 -0400 Subject: [PATCH] Fix function_schema name override bug (#872) ## Summary - ensure `name_override` is always used in `function_schema` - test name override when docstring info is disabled ## Testing - `make format` - `make lint` - `make mypy` - `make tests` Resolves #860 ------ https://chatgpt.com/codex/tasks/task_i_684f1cf885b08321b4dd3f4294e24ca2 --- src/agents/function_schema.py | 3 ++- tests/test_function_schema.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/agents/function_schema.py b/src/agents/function_schema.py index 1885669..dd1db1f 100644 --- a/src/agents/function_schema.py +++ b/src/agents/function_schema.py @@ -223,7 +223,8 @@ def function_schema( doc_info = None param_descs = {} - func_name = name_override or doc_info.name if doc_info else func.__name__ + # Ensure name_override takes precedence even if docstring info is disabled. + func_name = name_override or (doc_info.name if doc_info else func.__name__) # 2. Inspect function signature and get type hints sig = inspect.signature(func) diff --git a/tests/test_function_schema.py b/tests/test_function_schema.py index 5618d8a..54e7e2f 100644 --- a/tests/test_function_schema.py +++ b/tests/test_function_schema.py @@ -439,3 +439,15 @@ def test_schema_with_mapping_raises_strict_mode_error(): with pytest.raises(UserError): function_schema(func_with_mapping) + + +def test_name_override_without_docstring() -> None: + """name_override should be used even when not parsing docstrings.""" + + def foo(x: int) -> int: + return x + + fs = function_schema(foo, use_docstring_info=False, name_override="custom") + + assert fs.name == "custom" + assert fs.params_json_schema.get("title") == "custom_args"