
    
`i              	          d Z ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 dej        dej        fdZdej        dej        e         fd	Zdej        defd
Zdej        dej        ej        eej        e         ej        e         f                  fdZ G d dej                  Zdej        eef         de	ddfdZdS )zbAttribute docstrings parsing.

.. seealso:: https://peps.python.org/pep-0257/#what-is-a-docstring
    N)
ModuleType   )	DocstringDocstringParamnodereturnc                 "    t          | d          S )z<Return the constant's value if the given node is a constant.value)getattrr   s    l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/docstring_parser/attrdoc.pyast_get_constant_valuer      s    4!!!    c                    t          t          d          rt          j        |           S t          | t          j                  rt          t          |                     S t          | t          j                  r| j        S dS )z0Convert the AST node to source code as a string.unparseN)	hasattrastr   
isinstanceConstantstrr   Nameidr   s    r   ast_unparser      so    sI !{4   $%% 1)$//000$!! w4r   c                     t          | t          j                  oEt          | j        t          j                  o&t          t          | j                  t                    S )z2Return True if the given node is a literal string.)r   r   Exprr
   r   r   r   r   s    r   ast_is_literal_strr       sM     	4"" 	@tz3<00	@-dj993??r   c                    t          | t          j        t          j        f          rt          | t          j                  r| j        d         n| j        }t          |t          j                  rWd}t          | t          j                  rt          | j                  }d}| j	        rt          | j	                  }|j
        ||fS dS )z@Return name, type and default if the given node is an attribute.r   N)r   r   Assign	AnnAssigntargetstargetr   r   
annotationr
   r   )r   r!   type_strdefaults       r   ast_get_attributer%   )   s     $S]344 0)$
;;LDLOO 	 fch'' 	0H$.. 8&t77Gz 2%dj119h//4r   c            
           e Zd ZdZdZdZd Zdej        dej	        e
ej        e
ej        e
         ej        e
         f         f         fdZdS )AttributeDocstringsz6An ast.NodeVisitor that collects attribute docstrings.Nc                 (   | j         r9t          |          r*| j         \  }}}t          |j                  ||f| j        |<   t          |          | _         t          |t          j        t          j	        f          r| 
                    |           d S d S N)	prev_attrr   r   r
   	attr_docsr%   r   r   ClassDefModulegeneric_visit)selfr   	attr_name	attr_typeattr_defaults        r   visitzAttributeDocstrings.visitB   s    > 	066 	15.Iy,&tz22)DN9%
 +400dS\3:677 	%t$$$$$	% 	%r   	componentr   c                    i | _         d| _        	 t          j        t	          j        |                    }t          j        |          }t	          j        |          r| 	                    |           npt          |t          j                  rEt          |j        d         t          j                  r | 	                    |j        d                    n# t          $ r Y nw xY w| j         S )zGet attribute docstrings from the given component.

        :param component: component to process (class or module)
        :returns: for each attribute docstring, a tuple with (description,
            type, default)
        Nr   )r+   r*   textwrapdedentinspect	getsourcer   parseismoduler3   r   r-   bodyr,   OSError)r/   r4   sourcetrees       r   get_attr_docsz!AttributeDocstrings.get_attr_docsN   s     	)_W%6y%A%ABBF 9V$$D	** )

4    D#*-- )*	!cl3 3 ) 

49Q<(((  	 	 	D	 ~s   &C 
C! C!)__name__
__module____qualname____doc__r+   r*   r3   TAnyDictr   TupleOptionalr@    r   r   r'   r'   <   s        @@II
% 
% 
%	
QWS!*S/1:c?BCC	D     r   r'   obj	docstringc           	      *   t          d |j        D                       }t                                          |                                           D ]@\  }\  }}}||vr3t          d|g||||du|          }|j                            |           AdS )zAdd attribute docstrings found in the object's source code.

    :param obj: object from which to parse attribute docstrings
    :param docstring: Docstring object where found attributes are added
    :returns: list with names of added attributes
    c              3   $   K   | ]}|j         V  d S r)   )arg_name).0ps     r   	<genexpr>z+add_attribute_docstrings.<locals>.<genexpr>q   s$      66666666r   	attributeN)argsdescriptionrO   	type_nameis_optionalr$   )setparamsr'   r@   itemsr   metaappend)rK   rL   rY   rO   rU   rV   r$   params           r   add_attribute_docstringsr^   h   s     66Y%566666F++C006688) )33;	7 6!!"!8,'!##4/  E N!!%((() )r   )rD   r   r8   r6   typingrE   typesr   commonr   r   ASTrF   r   rI   r   r   boolr   rH   r%   NodeVisitorr'   Uniontyper^   rJ   r   r   <module>rg      s   
 


             - - - - - - - -" "QU " " " "
	cg 	!*S/ 	 	 	 	SW     
'ZQZ_ajo=>?   &) ) ) ) )#/ ) ) )X)	
z!	")/8)	) ) ) ) ) )r   