
    KiD              	          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
mZmZmZmZmZmZmZ dZdej$                  dej$                  fdZd	edej*                  e   fd
Z ej.                  dej0                        Z ej.                  d      Z ej.                  d      Z ej.                  d      Z ej.                  d      Z ej.                  d      Z G d d      Z G d de      Z  G d de      Z! G d de       Z" G d de       Z# G d de       Z$ G d de$      Z% G d  d!e!      Z& G d" d#e      Z'g  e"d$d%       e"d&d%       e"d'd%       e"d(d%       e"d)d*       e"d+d*       e"d,d*       e"d-d*       e"d.d/       e"d0d/       e#d1d2       e#d3d2       e#d4d5       e#d6d5       e"d7d8       e"d9d8       e$d:d;       e$d<d;       e%d=d>       e%d?d>       e'd@dA       e'dBdA       edCdD       edEdD       edFdG       edHdG       edIdJ       edKdJ       edLdM       edNdM       e&dOdP      Z( G dQ dR      Z)dSej*                  e   de	fdTZ*ejV                  dUfdVe	dWedXedefdYZ,y)[z_Numpydoc-style docstring parsing.

:see: https://numpydoc.readthedocs.io/en/latest/format.html
    N)dedent   )		DocstringDocstringDeprecatedDocstringExampleDocstringMetaDocstringParamDocstringRaisesDocstringReturnsDocstringStyleRenderingStyleiterablereturnc                 z    t        j                  |       \  }}t        |d        t        j                  |||      S )N)	fillvalue)	itertoolsteenextzip_longest)r   endleftrights       e/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docstring_parser/numpydoc.py	_pairwiser      s3    --)KD%  u<<    stringc                 D    | j                         } t        |       dkD  r| S y )Nr   )striplen)r   s    r   
_clean_strr       s     \\^F
6{Qr   z	^[^\s].*$flagsz(^(?P<name>.*?)(?:\s*:\s*(?P<type>.*?))?$z)(?P<type>.*?)(?:, optional|\(optional\))$zI(?P<type>.*?)(?:, default|\(default\))(?: | |=| = |= |: |)*(?P<value>.*)$z`(?<!\S)[Dd]efault(?:s to |(?:\s*(?:is|[=:])\s*|\s+))(?P<value>(?:['\"]).*?(?:['\"])|[\w\-\.]*\w)z(^(?:(?P<name>.*?)\s*:\s*)?(?P<type>.*?)$c                   d    e Zd ZdZdededdfdZedefd       Zdedej                  e
   fd	Zy)
Sectiona  Numpydoc section parser.

    :param title: section title. For most sections, this is a heading like
                  "Parameters" which appears on its own line, underlined by
                  en-dashes ('-') on the following line.
    :param key: meta key string. In the parsed ``DocstringMeta`` instance this
                will be the first element of the ``args`` attribute list.
    titlekeyr   Nc                      || _         || _        y N)r%   r&   )selfr%   r&   s      r   __init__zSection.__init__I   s    
r   c                 X    dt        | j                        z  }d| j                   d| dS )zRegular expression pattern matching this section's header.

        This pattern will match this instance's ``title`` attribute in
        an anonymous group.
        -z^(z)\s*?\nz\s*$)r   r%   )r)   dashess     r   title_patternzSection.title_patternM   s/     s4::&TZZLxt44r   textc              #   R   K   t        | j                  gt        |             yw)zParse ``DocstringMeta`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        )descriptionN)r   r&   r    )r)   r/   s     r   parsezSection.parseW   s       TXXJJt4DEEs   %')__name__
__module____qualname____doc__strr*   propertyr.   TIterabler   r2    r   r   r$   r$   ?   s[    c    5s 5 5F# F!**]"; Fr   r$   c                   N    e Zd ZdZdededefdZdedej                  e   fdZ	y)	
_KVSectionzBase parser for numpydoc sections with key-value syntax.

    E.g. sections that look like this:
        key
            value
        key2 : type
            values can also span...
            ... multiple lines
    r&   valuer   c                      y r(   r;   r)   r&   r>   s      r   _parse_itemz_KVSection._parse_itemk   s    r   r/   c              #     K   t        t        j                  |            D ]d  \  }}|j                         }||j	                         nd }||| }| j                  |j                         t        j                  |             f y w)N)r&   r>   )	r   KV_REGEXfinditerr   startrA   groupinspectcleandoc)r)   r/   match
next_matchrE   r   r>   s          r   r2   z_KVSection.parsen   s     !*8+<+<T+B!C 	E:IIKE(2(>*""$DCsOE""KKM)9)9%)@ #  		s   BB	N)
r3   r4   r5   r6   r7   r   rA   r9   r:   r2   r;   r   r   r=   r=   `   s=    s 3 = # !**]"; r   r=   c                   &    e Zd ZdZedefd       Zy)_SphinxSectionzBase parser for numpydoc sections with sphinx-style syntax.

    E.g. sections that look like this:
        .. title:: something
            possibly over multiple lines
    r   c                 "    d| j                    dS )Nz	^\.\.\s*(z)\s*::)r%   r)   s    r   r.   z_SphinxSection.title_pattern   s    DJJ<v..r   N)r3   r4   r5   r6   r8   r7   r.   r;   r   r   rL   rL   x   s"     /s / /r   rL   c                   $    e Zd ZdZdededefdZy)ParamSectionzParser for numpydoc parameter sections.

    E.g. any section that looks like this:
        arg_name
            arg_description
        arg_2 : type, optional
            descriptions can also span...
            ... multiple lines
    r&   r>   r   c                    t         j                  |      }d x}x}x}}||j                  d      }|j                  d      }|ht        j                  |      }||j                  d      }d}nd}t        j                  |      }	|	$d}|	j                  d      }|	j                  d      }t        |      dkD  r*|(t        j                  |      }	|	|	j                  d      }t        | j                  |gt        |      ||||      S )NnametypeTFr>   r   )argsr1   arg_name	type_nameis_optionaldefault)PARAM_KEY_REGEXrI   rF   PARAM_OPTIONAL_REGEXPARAM_DEFAULT_REGEXr   PARAM_DEFAULT_REGEX_IN_DESCsearchr	   r&   r    )
r)   r&   r>   rI   rU   rV   rW   rX   optional_matchdefault_matchs
             r   rA   zParamSection._parse_item   s   %%c*7;;;9;{W{{6*HF+I$!5!;!;I!F!- . 4 4V <I"&K"'K 3 9 9) D ,"&K - 3 3F ;I+11':G u:>go7>>uEM('--g6((H%"5)#
 	
r   N)r3   r4   r5   r6   r7   r	   rA   r;   r   r   rP   rP      s!    "
s "
3 "
> "
r   rP   c                   $    e Zd ZdZdededefdZy)RaisesSectionzParser for numpydoc raises sections.

    E.g. any section that looks like this:
        ValueError
            A description of what might raise ValueError
    r&   r>   r   c                 r    t        | j                  |gt        |      t        |      dkD  r|      S d       S )Nr   )rT   r1   rV   )r
   r&   r    r   r@   s      r   rA   zRaisesSection._parse_item   s>    ((C"5) X\c
 	
 04
 	
r   N)r3   r4   r5   r6   r7   r
   rA   r;   r   r   ra   ra      s!    
s 
3 
? 
r   ra   c                   (    e Zd ZdZdZdededefdZy)ReturnsSectionzParser for numpydoc returns sections.

    E.g. any section that looks like this:
        return_name : type
            A description of this returned value
        another_type
            Return names are optional, types are required
    Fr&   r>   r   c                     t         j                  |      }|#|j                  d      }|j                  d      }nd }d }t        | j                  gt        |      || j                  |      S )NrR   rS   )rT   r1   rV   is_generatorreturn_name)RETURN_KEY_REGEXrI   rF   r   r&   r    rf   )r)   r&   r>   rI   rg   rV   s         r   rA   zReturnsSection._parse_item   sk     &&s+++f-KF+IKI(("5)**#
 	
r   N)r3   r4   r5   r6   rf   r7   r   rA   r;   r   r   rd   rd      s)     L
s 
3 
3C 
r   rd   c                       e Zd ZdZdZy)YieldsSectionz0Parser for numpydoc generator "yields" sections.TN)r3   r4   r5   r6   rf   r;   r   r   rj   rj      s
    :Lr   rj   c                   :    e Zd ZdZdedej                  e   fdZy)DeprecationSectionz3Parser for numpydoc "deprecation warning" sections.r/   r   c              #      K   |j                  dd      d d gz   ^}}}|t        t        j                  |            }t	        | j
                  g|t        |             y w)N
r   )sepmaxsplit)rT   r1   version)splitr    rG   rH   r   r&   )r)   r/   rq   desc_s        r   r2   zDeprecationSection.parse   sb      JJ4!J<d|Kg..t45D!((z'7J
 	
s   A!A#N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   rl   rl      s"    =
# 
!**-@"A 
r   rl   c                   :    e Zd ZdZdedej                  e   fdZy)ExamplesSectiona  Parser for numpydoc examples sections.

    E.g. any section that looks like this:
        >>> import numpy.matlib
        >>> np.matlib.empty((2, 2))    # filled with random data
        matrix([[  6.76425276e-320,   9.79033856e-307], # random
                [  7.39337286e-309,   3.22135945e-309]])
        >>> np.matlib.empty((2, 2), dtype=int)
        matrix([[ 6600475,        0], # random
                [ 6586976, 22740995]])
    r/   r   c              #     K   t        |      j                         j                         }|rg }g }|r8|d   j                  d      sn#|j	                  |j                  d             |r8|r8|d   j                  d      rn#|j	                  |j                  d             |r8t        | j                  g|rdj                  |      nddj                  |             |ryyw)zParse ``DocstringExample`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        r   z>>>rn   N)snippetr1   )	r   r   
splitlines
startswithappendpopr   r&   join)r)   r/   linessnippet_linesdescription_liness        r   r2   zExamplesSection.parse  s      t""$//1M "Qx**51$$UYYq\2  8&&u-!((16  #
4A		-0t II&78  s   A'C&*9C&$?C&$C&N)	r3   r4   r5   r6   r7   r9   r:   r   r2   r;   r   r   rv   rv      s#    
# !**]"; r   rv   
ParametersparamParams	ArgumentsArgsOther Parametersother_paramzOther ParamszOther Argumentsz
Other ArgsReceivesreceivesReceiveRaisesraisesRaiseWarnswarnsWarn
Attributes	attribute	AttributeReturnsreturnsReturnYieldsyieldsYieldExamplesexamplesExampleWarningswarningsWarningzSee Alsosee_alsoRelatedNotesnotesNote
References
references	Reference
deprecateddeprecationc                       e Zd ZdZddej
                  ej                  eef      fdZ	d Z
defdZdej
                  e   d	efd
Zy)NumpydocParserz%Parser for numpydoc-style docstrings.Nsectionsc                     |xs t         }|D ci c]  }|j                  | c}| _        | j                          yc c}w )z[Setup sections.

        :param sections: Recognized sections or None to defaults.
        N)DEFAULT_SECTIONSr%   r   _setup)r)   r   ss      r   r*   zNumpydocParser.__init__C  s7    
 //-56!6 7s   <c                     t        j                  dj                  d | j                  j	                         D              t         j
                        | _        y )N|c              3   4   K   | ]  }|j                     y wr(   )r.   ).0r   s     r   	<genexpr>z(NumpydocParser._setup.<locals>.<genexpr>N  s     F!aooFs   r!   )recompiler}   r   valuesM	titles_rerN   s    r   r   zNumpydocParser._setupL  s8    IIFt}}/C/C/EFF$$
r   sectionc                 V    || j                   |j                  <   | j                          y)zLAdd or replace a section.

        :param section: The new section.
        N)r   r%   r   )r)   r   s     r   add_sectionzNumpydocParser.add_sectionR  s     (/gmm$r   r/   r   c                 L   t        t        j                        }|s|S t        j                  |      }| j
                  j                  |      }|r'|d|j                          }||j                         d }n|}d}|j                  dd      }|d   xs d|_	        t        |      dkD  rN|d   xs d}|j                  d      |_        |j                  d      |_        |j                         xs d|_        t#        | j
                  j%                  |            D ]  \  }}t'        d |j)                         D              }	| j*                  |	   }
|j-                         }||j                         nd}|j.                  j1                  |
j3                  |||               |S )	zaParse the numpy-style docstring into its components.

        :returns: parsed docstring
        )styleN rn   r   r   z

c              3   &   K   | ]	  }||  y wr(   r;   )r   gs     r   r   z'NumpydocParser.parse.<locals>.<genexpr>|  s     DqamDs   )r   r   NUMPYDOCrG   rH   r   r]   rE   rr   short_descriptionr   rz   blank_after_short_descriptionendswithblank_after_long_descriptionr   long_descriptionr   rD   r   groupsr   r   metaextendr2   )r)   r/   retrI   
desc_chunk
meta_chunkpartslong_desc_chunk	nextmatchr%   factoryrE   r   s                r   r2   zNumpydocParser.parse[  s   
 n556J % %%d+o.Jekkmo.JJJ   q) %a 0Du:>#Ahn"O0?0J0J1C- 0?/G/G/OC,#2#8#8#:#BdC  )$..*A*A**M N 	BE9DELLNDDEmmE*G IIKE'0'<)//#$CHHOOGMM*U3*?@A	B 
r   r(   )r3   r4   r5   r6   r9   OptionalDictr7   r$   r*   r   r   r   r2   r;   r   r   r   r   @  sS    /AFF3<,@!A 
7 *!**S/ *i *r   r   r/   c                 4    t               j                  |       S )zYParse the numpy-style docstring into its components.

    :returns: parsed docstring
    )r   r2   )r/   s    r   r2   r2     s    
 !!$''r   z    	docstringrendering_styleindentc           	      
   dt         j                  t        t        t        f   ffddt
        dt         j                  t         j                     ffd}g | j                  rj                  | j                         | j                  rj                  d       | j                  rd}| j                  j                  r|d| j                  j                   z  }| j                  j                  r%| j                  j                  j                         }ng }d	 }j                  |j                  |g|z                | j                   rj                  | j                          | j"                  rj                  d        |d
| j$                  xs g D cg c]  }|j&                  d   dk(  s| c}        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j(                  xs g D cg c]  }|j*                  s| c}        |d| j(                  xs g D cg c]  }|j*                  s| c}       | j,                  rU| j(                  sI| j,                  }j                  |rdnd       j                  dt/        d         z          |        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j$                  xs g D cg c]  }|j&                  d   dk(  r| c}        |d| j0                  xs g D cg c]  }|j&                  d   dk(  s| c}        |d| j0                  xs g D cg c]  }|j&                  d   dk(  s| c}       t/        | j2                        dkD  rj                  d       j                  d       j                  d       | j2                  D ]Q  }	|	j4                  rj                  |	j4                         |	j                  s7j                  |	j                         S | j6                  D ]  }
t9        |
t:        t        t        t        t<        f      r)j                  d       j                  |
j&                  d   j?                  dd      jA                                j                  dt/        |
j&                  d         z         |
j                  sj                  |
j                          d	j                        S c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )a  Render a parsed docstring into docstring text.

    :param docstring: parsed docstring representation
    :param rendering_style: the style to render docstrings
    :param indent: the characters used as indentation in the docstring string
    :returns: docstring text
    onec                 Z   t        | t              r| j                  }nt        | t              r| j                  }nd }| j
                  r|r|d| j
                   z  }n| j
                  r| j
                  }n|sd}t        | t              rA| j                  dvr|d| j                   z  }n | j                  s| j                  dk(  r|dz  }| j                  rBd j                  |g| j                  j                         z         }j                  |       y j                  |       y )Nz : r   )NNonez
, default=r   z
, optionalrn   )
isinstancer	   rU   r   rg   rV   rX   rW   r1   r}   ry   r{   )r   headbodyr   r   s      r   process_onezcompose.<locals>.process_one  s     c>*<<D-.??DD==Tc#--))D]]==DD
 c>*{{.0*S[[M22CKK6$9$??x=%%tfs/I/I/K&KLDLLLLr   rR   rT   c                     |rRj                  d       j                  |        j                  dt        d         z         |D ]
  } |        y y )Nr   r,   )r{   r   )rR   rT   argr   r   s      r   process_sectzcompose.<locals>.process_sect  sS    LLLLLLs59~-. !C !	 r   r   z.. deprecated:: rn   r   r   r   r   r   r   r   r,   r   r   r   r   r   r   r   r   r   r   z--------rt   )!r9   Unionr	   r   r
   r7   ListAnyr   r{   r   r   rq   r1   ry   r}   r   r   paramsrT   many_returnsrf   r   r   r   r   rx   r   r   r   r   replacer%   )r   r   r   r   firstrestro   itemr   exampler   r   r   s     `        @@r   composer     s   WW^%5FG@!3 !affQUUm ! E""Y001..R!  ((q..66788E  ,,((44??ADD6(mSXXugn-.!!Y//0--R#**0bL$DIIaLG4KL
  "((.B	
yy|{* 	
  "..4"	
$$ 	
 #006BL$$:K:KL
 !7!7X)4S3uRy>)*C "((.B	
yy|z) 	
  "((.B	
yy|}, 	
 #**0bM$DIIaLH4LM
 #**0bL$DIIaLG4KL
 9"RZ Z  )) 	2GW__-""W001		2  +#  	
 RTYYq\))#r288:;S3tyy|,,-LL))*%+( 99Uu 	M
	
	
 	M	
	
 	N
 	MsH    T.
8T.
T3
T8
 T=
T=
U

U
U
U
9U
U
r(   )-r6   rG   r   r   typingr9   textwrapr   commonr   r   r   r   r	   r
   r   r   r   r:   r   r7   r   r    r   r   rC   rY   rZ   r[   r\   rh   r$   r=   rL   rP   ra   rd   rj   rl   rv   r   r   r2   COMPACTr   r;   r   r   <module>r      s  
   	  
 
 
=

 = =s qzz#  2::l"$$/"**HI!rzz"NO  !bjjP  )bjjg  2::IJ F FB 0
/W 
/-
: -
`
J 
 
Z 
<N 
 
#g #L w' 7#  g&  !	 
 #]3  /  "M2  }-  Z(  J'  (H%  '8$  '7#  &'"  {+   k*! " 9i(# $ 8Y'% & (H%' ( '8$) * J
++ , Iz*- . J
#/ 0 Iz"1 2 J
#3 4 Iz"5 6 GW7 8 FG9 : L,'; < K&= > |]3?  FE EP(

3 (I ( '5&<&<	hh $h 	h
 	hr   