o
    i                     @  s   U d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ d dlmZmZmZ er?dd	lmZ ed
 Zd'ddZd(ddZdg ddfdg ddfd g d!d"fgZd#ed$< ed%d& ZdS ))    )annotationsN)Callable)contextmanager)	Signature)TYPE_CHECKINGAnyLiteralcast)	DocstringDocstringSectionKindObject   )DocstringFormat)googlenumpysphinxfuncCallable[..., Any]sigr   docstring_formatr   return!tuple[str | None, dict[str, str]]c                C  sD  | j }|du rdi fS tt|}|dkrt|n|}t|d||dddd}t  | }W d   n1 s8w   Y  i }tdd |D d }	rSd	d
 |	jD }d}
tdd |D d }rd|j}
tdd |D d }r|jd }|j	}|j
}|rd| dnd}d| d| d}|
rd|
 d| }
|
|fS |}
|
|fS )a  Extract the function description and parameter descriptions from a function's docstring.

    The function parses the docstring using the specified format (or infers it if 'auto')
    and extracts both the main description and parameter descriptions. If a returns section
    is present in the docstring, the main description will be formatted as XML.

    Returns:
        A tuple containing:
        - str: Main description string, which may be either:
            * Plain text if no returns section is present
            * XML-formatted if returns section exists, including <summary> and <returns> tags
        - dict[str, str]: Dictionary mapping parameter names to their descriptions
    Nautor   F)returns_named_valuereturns_multiple_items)linenoparserparentparser_optionsc                 s       | ]}|j tjkr|V  qd S N)kindr   
parameters.0p r&   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/_griffe.py	<genexpr>9       z#doc_descriptions.<locals>.<genexpr>c                 S  s   i | ]}|j |jqS r&   )namedescriptionr#   r&   r&   r'   
<dictcomp>:   s    z$doc_descriptions.<locals>.<dictcomp> c                 s  r   r    )r!   r   textr#   r&   r&   r'   r(   =   r)   c                 s  r   r    )r!   r   returnsr#   r&   r&   r'   r(   @   r)   r   z<type>z</type>
z
<returns>
z<description>z</description>
</returns>z	<summary>z</summary>
)__doc__r	   GriffeObject_infer_docstring_styler
   _disable_griffe_loggingparsenextvaluer+   
annotation)r   r   r   docr   docstring_style	docstringsectionsparamsr"   	main_descmainreturn_return_statementreturn_descreturn_typetype_tag
return_xmlr&   r&   r'   doc_descriptions   s@   


rE   r8   strDocstringStylec                   s8   t D ]\}} fdd|D }t|r|  S qdS )z%Simplistic docstring style inference.c                 3  s,    | ]}t | t jt jB V  qd S r    )researchformat
IGNORECASE	MULTILINE)r$   replacementr8   patternr&   r'   r(   R   s    
z)_infer_docstring_style.<locals>.<genexpr>r   )_docstring_style_patternsany)r8   replacementsstylematchesr&   rN   r'   r2   O   s   r2   z&\n[ \t]*:{0}([ \t]+\w+)*:([ \t]+.+)?\n)param	parameterargargumentkeykeywordtypevarivarcvarvartyper/   r   rtyperaisesraiseexcept	exceptionr   z!\n[ \t]*{0}:([ \t]+.+)?\n[ \t]+.+)args	argumentsr<   r"   zkeyword argszkeyword argumentsz
other argszother argumentszother paramsother parametersra   
exceptionsr/   yieldsreceivesexamples
attributes	functionsmethodsclassesmoduleswarnswarningsr   z\n[ \t]*{0}\n[ \t]*---+\n)
deprecatedr"   rg   r/   ri   rj   ra   rq   rl   rm   rn   ro   rp   r   z+list[tuple[str, list[str], DocstringStyle]]rP   c                  c  s0    t j } t jt j d V  t j|  d S r    )loggingrootgetEffectiveLevelsetLevelERROR)	old_levelr&   r&   r'   r3      s
   
r3   )r   r   r   r   r   r   r   r   )r8   rF   r   rG   )
__future__r   _annotationsrt   rH   collections.abcr   
contextlibr   inspectr   typingr   r   r   r	   griffer
   r   r   r1   toolsr   rG   rE   r2   rP   __annotations__r3   r&   r&   r&   r'   <module>   s8    

=L