Skip to content

Commit

Permalink
Clean up multi-line docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed Jul 18, 2024
1 parent 4b469ea commit 30e8c4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arcade/arcade/sdk/tool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import os
from typing import Any, Callable, Optional, TypeVar, Union

Expand All @@ -19,7 +20,7 @@ def decorator(func: Callable) -> Callable:
tool_name = name or snake_to_pascal_case(func_name)

setattr(func, "__tool_name__", tool_name) # noqa: B010 (Do not call `setattr` with a constant attribute value)
setattr(func, "__tool_description__", desc or func.__doc__) # noqa: B010
setattr(func, "__tool_description__", desc or inspect.cleandoc(func.__doc__)) # noqa: B010
setattr(func, "__tool_requires_auth__", requires_auth) # noqa: B010

return func
Expand Down
14 changes: 14 additions & 0 deletions arcade/tests/tool/test_create_tool_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def func_with_docstring_description():
pass


@tool
def func_with_multiline_docstring_description():
"""
Docstring description
on multiple lines
"""
pass


@tool(name="MyCustomTool", desc="A function with a very cool description")
def func_with_name_and_description():
pass
Expand Down Expand Up @@ -163,6 +172,11 @@ def func_with_complex_return() -> list[dict[str, str]]:
{"description": "Docstring description"},
id="func_with_docstring_description",
),
pytest.param(
func_with_multiline_docstring_description,
{"description": "Docstring description\non multiple lines"},
id="func_with_multiline_docstring_description",
),
pytest.param(
func_with_name_and_description,
{"name": "MyCustomTool", "description": "A function with a very cool description"},
Expand Down

0 comments on commit 30e8c4f

Please sign in to comment.