mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 16:18:03 +00:00
Use empty string instead of 'No description available' for missing descriptions
This commit is contained in:
1 parent
5cc4086c4f
commit
2737dd2b3f
3 files changed
+64
-3
No files matched your search
+4
-2
@@ -64,9 +64,11 @@ def make_tool(
|
||||
if docstring.description:
|
||||
func_doc = f"{docstring.description.strip().strip('.')}."
|
||||
else:
|
||||
func_doc = "No description available."
|
||||
func_doc = ""
|
||||
if (docstring.returns) and (docstring_returns := docstring.returns.description):
|
||||
func_doc = f"{func_doc} Returns {docstring_returns.strip().strip('.')}."
|
||||
# Only add a space before "Returns" if func_doc is not empty
|
||||
prefix = " " if func_doc else ""
|
||||
func_doc = f"{func_doc}{prefix}Returns {docstring_returns.strip().strip('.')}."
|
||||
|
||||
# Parse the parameter descriptions from the docstring and add pass its description
|
||||
# to the parameters schema.
|
||||
|
||||
@@ -218,7 +218,7 @@ def test_make_tool_missing_description() -> None:
|
||||
mcp_tool = make_tool(tool)
|
||||
|
||||
assert mcp_tool.name == "no_description"
|
||||
assert mcp_tool.description == "No description available. Returns A result."
|
||||
assert mcp_tool.description == "Returns A result."
|
||||
assert mcp_tool.parameters["properties"]["param"]["description"] == "The parameter."
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Simple test for the make_tool function."""
|
||||
|
||||
import docstring_parser
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
def make_tool_simplified(func_doc: str) -> str:
|
||||
"""Simplified version of make_tool function to test our fix."""
|
||||
docstring = docstring_parser.parse(func_doc)
|
||||
|
||||
# Mount the tool description as a combination of the docstring description and
|
||||
# the return value description, if it exists.
|
||||
if docstring.description:
|
||||
func_doc = f"{docstring.description.strip().strip('.')}."
|
||||
else:
|
||||
func_doc = ""
|
||||
if (docstring.returns) and (docstring_returns := docstring.returns.description):
|
||||
# Only add a space before "Returns" if func_doc is not empty
|
||||
prefix = " " if func_doc else ""
|
||||
func_doc = f"{func_doc}{prefix}Returns {docstring_returns.strip().strip('.')}."
|
||||
|
||||
return func_doc
|
||||
|
||||
|
||||
def test_with_description():
|
||||
"""Test with a normal docstring that has a description."""
|
||||
doc = """This is a test function.
|
||||
|
||||
:param name: The person's name
|
||||
:param age: The person's age
|
||||
:return: A greeting message
|
||||
"""
|
||||
result = make_tool_simplified(doc)
|
||||
assert result == "This is a test function. Returns A greeting message."
|
||||
|
||||
|
||||
def test_without_description():
|
||||
"""Test with a docstring that has no description."""
|
||||
doc = """
|
||||
:param name: The person's name
|
||||
:param age: The person's age
|
||||
:return: A greeting message
|
||||
"""
|
||||
result = make_tool_simplified(doc)
|
||||
assert result == "Returns A greeting message."
|
||||
|
||||
|
||||
def test_empty_docstring():
|
||||
"""Test with an empty docstring."""
|
||||
doc = ""
|
||||
result = make_tool_simplified(doc)
|
||||
assert result == ""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_with_description()
|
||||
test_without_description()
|
||||
test_empty_docstring()
|
||||
print("All tests passed!")
|
||||
Reference in new issue
Block a user