
    $j                        d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ dZ ej        d	          Ze                    ej                    ed
           G d d                      ZddZdS )u  Extract descriptions from function docstrings.

Uses griffelib to parse Google, NumPy, and Sphinx-style docstrings. The
interface is intentionally narrow — a single function returning a
`ParsedDocstring` — so the implementation can be swapped without touching
callers.
    )annotationsN)Callable)	dataclassfield)Any)	DocstringDocstringSectionKind)googlenumpysphinxgriffeT)frozenc                  D    e Zd ZU dZdZded<    ee          Zded<   dS )ParsedDocstringzJThe extracted description and per-parameter descriptions from a docstring.Nz
str | Nonedescription)default_factoryzdict[str, str]
parameters)	__name__
__module____qualname____doc__r   __annotations__r   dictr        k/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fastmcp/utilities/docstring_parsing.pyr   r      sG         TT"K""""!&t!<!<!<J<<<<<<r   r   fnCallable[..., Any]returnc                   t          j        |           }|st                      S t          D ]}t	          |d|          }|                                }d}i }|D ]O}|j        t          j        k    r
||j	        }!|j        t          j
        k    r|j	        D ]}|j        ||j        <   P|rt          ||          c S t          |          S )a,  Parse a function's docstring into a summary and parameter descriptions.

    Tries Google, NumPy, and Sphinx parsers in order, using the first one that
    successfully extracts parameter descriptions. If none do, returns the full
    docstring as the description with no parameter descriptions.
       )linenoparserN)r   r   )r   )inspectgetdocr   _PARSERSr   parsekindr	   textvaluer   r   name)	r   docr#   	docstringsectionsr   r   sectionparams	            r   parse_docstringr1   #   s    .

C !     S Sc!F;;;	??$$"&%'
 	? 	?G|3888[=P%m!5!@@@$] ? ?E-2->Juz** 	S"{zRRRRRR	S s++++r   )r   r   r   r   )r   
__future__r   r$   loggingcollections.abcr   dataclassesr   r   typingr   r   r   r	   r&   	getLoggerloggersetLevelERRORr   r1   r   r   r   <module>r;      s    # " " " " "   $ $ $ $ $ $ ( ( ( ( ( ( ( (       2 2 2 2 2 2 2 2(		8	$	$     $= = = = = = = =, , , , , ,r   