
    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y)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    GC:\Projects\mas-dev\.venv\Lib\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 y)z0Convert the AST node to source code as a string.unparseN)	hasattrastr   
isinstanceConstantstrr   Nameidr   s    r   ast_unparser      sT    sI{{4  $%)$/00$!wwr   c                     t        | t        j                        xrI t        | j                  t        j                        xr# 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       sI     	4" 	@tzz3<<0	@-djj93?r   c                    t        | t        j                  t        j                  f      rt        | t        j                        r| j                  d   n| j
                  }t        |t        j                        rcd}t        | t        j                        rt        | j                        }d}| j                  rt        | j                        }|j                  ||fS y)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)$

;DLLO 	 fchh'H$.&t7Gzz%djj199h//r   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y)AttributeDocstringsz6An ast.NodeVisitor that collects attribute docstrings.Nc                 4   | j                   r@t        |      r5| j                   \  }}}t        |j                        ||f| j                  |<   t        |      | _         t        |t        j                  t        j                  f      r| j                  |       y y 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615.Iy,&tzz2)DNN9%
 +40dS\\3::67t$ 8r   	componentr   c                    i | _         d| _        	 t        j                  t	        j
                  |            }t        j                  |      }t	        j                  |      r| j                  |       | j                   S t        |t        j                        rEt        |j                  d   t        j                        r| j                  |j                  d          | j                   S # t        $ r Y | j                   S w xY w)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%6%6y%ABF 99V$D	*

4 
 ~~	 D#**-*		!cll3 

499Q<(~~  	 ~~	s   (C* *	D D)__name__
__module____qualname____doc__r+   r*   r3   TAnyDictr   TupleOptionalr@    r   r   r'   r'   <   s[    @II
%	
QWWS!**S/1::c?BCC	Dr   r'   obj	docstringc           	         t        d |j                  D              }t               j                  |       j	                         D ]>  \  }\  }}}||vst        d|g||||du|      }|j                  j                  |       @ y)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   4   K   | ]  }|j                     y wr)   )arg_name).0ps     r   	<genexpr>z+add_attribute_docstrings.<locals>.<genexpr>q   s     6%5%5s   	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     6Y%5%566F++C0668 	43;	7 6!"!8,'!##4/E NN!!%( 	9r   )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   
      -" "QUU "
	cgg 	!**S/ 	SWW  
''ZZQZZ_ajjo=>?&)#// )X)	
z!	")/8)	)r   