
    h              	          S r SSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  S\R                  S\R                  4S jrS\R                  S\R                  \   4S	 jrS\R                  S\4S
 jrS\R                  S\R                  \R&                  \\R                  \   \R                  \   4      4S jr " S S\R*                  5      rS\R.                  \\4   S\	SS4S jrg)zbAttribute docstrings parsing.

.. seealso:: https://peps.python.org/pep-0257/#what-is-a-docstring
    N)
ModuleType   )	DocstringDocstringParamnodereturnc                     [        U S5      $ )z<Return the constant's value if the given node is a constant.value)getattrr   s    R/home/james-whalen/.local/lib/python3.13/site-packages/docstring_parser/attrdoc.pyast_get_constant_valuer      s    4!!    c                    [        [        S5      (       a  [        R                  " U 5      $ [        U [        R                  5      (       a  [        [        U 5      5      $ [        U [        R                  5      (       a  U R                  $ g)z0Convert the AST node to source code as a string.unparseN)	hasattrastr   
isinstanceConstantstrr   Nameidr   s    r   ast_unparser      s]    sI{{4  $%%)$/00$!!wwr   c                     [        U [        R                  5      =(       aN    [        U R                  [        R                  5      =(       a#    [        [        U R                  5      [        5      $ )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                    [        U [        R                  [        R                  45      (       a  [        U [        R                  5      (       a  U R                  S   OU R
                  n[        U[        R                  5      (       al  Sn[        U [        R                  5      (       a  [        U R                  5      nSnU R                  (       a  [        U R                  5      nUR                  X#4$ g)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)$

;;DLLO 	 fchh''H$..&t7Gzz%djj199h//r   c            
           \ rS rSrSrSrSrS rS\R                  S\R                  \\R                  \\R                  \   \R                  \   4   4   4S jrSrg)	AttributeDocstrings<   z6An ast.NodeVisitor that collects attribute docstrings.Nc                 P   U R                   (       aD  [        U5      (       a4  U R                   u  p#n[        UR                  5      UU4U R                  U'   [        U5      U l         [        U[        R                  [        R                  45      (       a  U R                  U5        g g N)	prev_attrr   r   r
   	attr_docsr%   r   r   ClassDefModulegeneric_visit)selfr   	attr_name	attr_typeattr_defaults        r   visitAttributeDocstrings.visitB   s    >>06615.I,&tzz2)DNN9%
 +40dS\\3::677t$ 8r   	componentr   c                 0   0 U l         SU l         [        R                  " [        R
                  " U5      5      n[        R                  " U5      n[        R                  " U5      (       a  U R                  U5        U R                   $ [        U[        R                  5      (       aJ  [        UR                  S   [        R                  5      (       a  U R                  UR                  S   5        U R                   $ ! [         a     U R                   $ f = f)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ismoduler4   r   r.   bodyr-   OSError)r0   r6   sourcetrees       r   get_attr_docs!AttributeDocstrings.get_attr_docsN   s     	)__W%6%6y%ABF 99V$D	**

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

499Q<(~~  	 ~~	s   *C= =
DD)r,   r+   )__name__
__module____qualname____firstlineno____doc__r,   r+   r4   TAnyDictr   TupleOptionalrB   __static_attributes__ r   r   r'   r'   <   s[    @II
%	
QWWS!**S/1::c?BCC	Dr   r'   obj	docstringc           
         [        S UR                   5       5      n[        5       R                  U 5      R	                  5        H=  u  nu  pEnX2;  d  M  [        SU/UUUUSLUS9nUR                  R                  U5        M?     g)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   8   #    U  H  oR                   v   M     g 7fr*   )arg_name).0ps     r   	<genexpr>+add_attribute_docstrings.<locals>.<genexpr>q   s     6%5%5s   	attributeN)argsdescriptionrT   	type_nameis_optionalr$   )setparamsr'   rB   itemsr   metaappend)rP   rQ   r_   rT   r[   r\   r$   params           r   add_attribute_docstringsrd   h   s     6Y%5%566F++C0668 	43;7 !"!8,'!##4/E NN!!%( 	9r   )rH   r   r:   r8   typingrI   typesr   commonr   r   ASTrJ   r   rM   r   r   boolr   rL   r%   NodeVisitorr'   Uniontyperd   rO   r   r   <module>rm      s   
      -" "QUU "
	cgg 	!**S/ 	SWW  
''ZZQZZ_ajjo=>?&)#// )X)	
z!	")/8)	)r   