in src/agents/function_schema.py [0:0]
def _detect_docstring_style(doc: str) -> DocstringStyle:
scores: dict[DocstringStyle, int] = {"sphinx": 0, "numpy": 0, "google": 0}
# Sphinx style detection: look for :param, :type, :return:, and :rtype:
sphinx_patterns = [r"^:param\s", r"^:type\s", r"^:return:", r"^:rtype:"]
for pattern in sphinx_patterns:
if re.search(pattern, doc, re.MULTILINE):
scores["sphinx"] += 1
# Numpy style detection: look for headers like 'Parameters', 'Returns', or 'Yields' followed by
# a dashed underline
numpy_patterns = [
r"^Parameters\s*\n\s*-{3,}",
r"^Returns\s*\n\s*-{3,}",
r"^Yields\s*\n\s*-{3,}",
]
for pattern in numpy_patterns:
if re.search(pattern, doc, re.MULTILINE):
scores["numpy"] += 1
# Google style detection: look for section headers with a trailing colon
google_patterns = [r"^(Args|Arguments):", r"^(Returns):", r"^(Raises):"]
for pattern in google_patterns:
if re.search(pattern, doc, re.MULTILINE):
scores["google"] += 1
max_score = max(scores.values())
if max_score == 0:
return "google"
# Priority order: sphinx > numpy > google in case of tie
styles: list[DocstringStyle] = ["sphinx", "numpy", "google"]
for style in styles:
if scores[style] == max_score:
return style
return "google"