
    bMh                    z    d Z ddlmZ ddlZddlZddlZddlmZ  G d dej                  Z	ddZ
ddZdddZdS )z4Utilities related to attribute docstring extraction.    )annotationsN)Anyc                  <     e Zd Zd fdZd fdZdd	ZddZ xZS )DocstringVisitorreturnNonec                r    t                                                       d | _        i | _        d | _        d S N)super__init__targetattrsprevious_node_type)self	__class__s    c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pydantic/_internal/_docs_extraction.pyr   zDocstringVisitor.__init__   s5    "&%'
8<    nodeast.ASTr   c                r    t                                          |          }t          |          | _        |S r
   )r   visittyper   )r   r   node_resultr   s      r   r   zDocstringVisitor.visit   s,    ggmmD))"&t**r   ast.AnnAssignc                j    t          |j        t          j                  r|j        j        | _        d S d S r
   )
isinstancer   astNameid)r   r   s     r   visit_AnnAssignz DocstringVisitor.visit_AnnAssign   s1    dk38,, 	)+.DKKK	) 	)r   ast.Exprc                *   t          |j        t          j                  rot          |j        j        t                    rR| j        t          j        u rAt          j        |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   	docstrings      r   
visit_ExprzDocstringVisitor.visit_Expr   s    tz3<00	4:+S11	 '3=88()9::I{ 4*3
4;'DKKK	 	 	 	 98r   )r   r   )r   r   r   r   )r   r   r   r   )r   r!   r   r   )__name__
__module____qualname__r   r   r    r*   __classcell__)r   s   @r   r   r      s        = = = = = =     
) ) ) )	 	 	 	 	 	 	 	r   r   source	list[str]r   r%   c                    t          j        d                    |                     }|                    d          rd| }|S )N ) 	zdef dedent_workaround():
)textwrapdedentjoin
startswith)r/   dedent_sources     r   _dedent_source_linesr:   (   sH    OBGGFOO44M,, E E]DDr   cls	type[Any]list[str] | Nonec                v   t          j                    }|r"t          j        |          t          j        |           u r|j        }	 t          j        |          \  }}t          j        ||dz
  d                    }t          |          }	 t          j        |          }|j	        d         }t          |t          j                  r|j        dk    r|j	        d         }t          |t          j                  r|j        | j        k    r|S n # t          $ r Y nw xY w# t           $ r Y nw xY w|j        }| d S d S )N   r   dedent_workaround)r'   currentframe	getmodulef_lineno
findsourcegetblockr:   r   parsebodyr   FunctionDefnameClassDefr+   SyntaxErrorOSErrorf_back)	r;   framelnumlines_block_linesr9   
block_treestmts	            r   _extract_source_from_framerU   3   si    ""E
 U##w'8'='===>D+"-e44q &.uTAXZZ/@AA 4[ A A
+!$=!9!9J &?1-D!$88 ,TYJ]=]=]#y|!$55 +$)s|:S:S** #   D     & 1      s$   D D 
DD
D*)D*Fuse_inspectbooldict[str, str]c                   |r+	 t          j        |           \  }}n!# t          $ r i cY S w xY wt          |           }|si S t	          |          }t                      }|                    t          j        |                     |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.
    )
r'   getsourcelinesrL   rU   r:   r   r   r   rF   r   )r;   rV   r/   rQ   r9   visitors         r   extract_docstrings_from_clsr\   Q   s      1	.s33IFAA 	 	 	III	 ,C00 	(00M  GMM#)M**+++=s    ++)r/   r0   r   r%   )r;   r<   r   r=   )F)r;   r<   rV   rW   r   rX   )__doc__
__future__r   r   r'   r5   typingr   NodeVisitorr   r:   rU   r\    r   r   <module>rb      s    : : " " " " " " 



            s   :      <      r   