o
    Ú­j  ã                   @  sr   d Z ddlmZ ddlZddlZddlZddlZddlmZ G dd„ dej	ƒZ
ddd„Zddd„Zdddd„ZdS )z4Utilities related to attribute docstring extraction.é    )ÚannotationsN)ÚAnyc                      s@   e Zd Zd‡ fdd„Zd‡ fdd	„Zddd„Zddd„Z‡  ZS )ÚDocstringVisitorÚreturnÚNonec                   s    t ƒ  ¡  d | _i | _d | _d S ©N)ÚsuperÚ__init__ÚtargetÚattrsÚprevious_node_type)Úself©Ú	__class__© ú`/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pydantic/_internal/_docs_extraction.pyr	      s   

zDocstringVisitor.__init__Únodeúast.ASTr   c                   s   t ƒ  |¡}t|ƒ| _|S r   )r   ÚvisitÚtyper   )r   r   Únode_resultr   r   r   r      s   
zDocstringVisitor.visitúast.AnnAssignc                 C  s    t |jtjƒr|jj| _d S d S r   )Ú
isinstancer
   ÚastÚNameÚid)r   r   r   r   r   Úvisit_AnnAssign   s   ÿz DocstringVisitor.visit_AnnAssignúast.Exprc                 C  s^   t |jtjƒr)t |jjtƒr+| jtju r-t |jj¡}| j	r$|| j
| j	< d | _	d S d S d S d S r   )r   Úvaluer   ÚConstantÚstrr   Ú	AnnAssignÚinspectÚcleandocr
   r   )r   r   Ú	docstringr   r   r   Ú
visit_Expr   s   ÿþ
øzDocstringVisitor.visit_Expr)r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__r	   r   r   r%   Ú__classcell__r   r   r   r   r      s
    
r   Úsourceú	list[str]r   r    c                 C  s(   t  d | ¡¡}| d¡rd|› �}|S )NÚ )ú ú	zdef dedent_workaround():
)ÚtextwrapÚdedentÚjoinÚ
startswith)r*   Údedent_sourcer   r   r   Ú_dedent_source_lines)   s   

r4   Úclsú	type[Any]úlist[str] | Nonec           	      C  sä   t  ¡ }|rpt  |¡t  | ¡u ri|j}z	t  |¡\}}W n	 ty%   Y nDw t  ||d d … ¡}t|ƒ}zt 	|¡}W n	 t
yE   Y n$w |jd }t|tjƒr[|jdkr[|jd }t|tjƒri|j| jkri|S |j}|sd S d S )Né   r   Údedent_workaround)r"   ÚcurrentframeÚ	getmoduleÚf_linenoÚ
findsourceÚOSErrorÚgetblockr4   r   ÚparseÚSyntaxErrorÚbodyr   ÚFunctionDefÚnameÚClassDefr&   Úf_back)	r5   ÚframeÚlnumÚlinesÚ_Úblock_linesr3   Ú
block_treeÚstmtr   r   r   Ú_extract_source_from_frame4   s.   ýÿ

èrN   FÚuse_inspectÚboolúdict[str, str]c                 C  sl   |st jdkrz	t | ¡\}}W n ty   i  Y S w t| ƒ}|s$i S t|ƒ}tƒ }| t	 
|¡¡ |jS )aX  Map model attributes and their corresponding docstring.

    Args:
        cls: The class of the Pydantic model to inspect.
        use_inspect: Whether to skip usage of frames to find the object and use
            the `inspect` module instead.

    Returns:
        A mapping containing attribute names and their corresponding docstring.
    )é   é   )ÚsysÚversion_infor"   Úgetsourcelinesr>   rN   r4   r   r   r   r@   r   )r5   rO   r*   rJ   r3   Úvisitorr   r   r   Úextract_docstrings_from_clsR   s   ÿrX   )r*   r+   r   r    )r5   r6   r   r7   )F)r5   r6   rO   rP   r   rQ   )Ú__doc__Ú
__future__r   r   r"   rT   r/   Útypingr   ÚNodeVisitorr   r4   rN   rX   r   r   r   r   Ú<module>   s    

