o
    ì6WjëD  ã                	   @   sâ  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 d^dejdejfdd	„Zd
edeje fdd„Zejdejd�Ze d¡Ze d¡Ze d¡Ze d¡Ze d¡ZG dd„ dƒZG dd„ deƒZ G dd„ deƒZ!G dd„ de ƒZ"G dd„ de ƒZ#G dd„ de ƒZ$G d d!„ d!e$ƒZ%G d"d#„ d#e!ƒZ&G d$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"d0d1ƒ‘e"d2d1ƒ‘e#d3d4ƒ‘e#d5d4ƒ‘e#d6d7ƒ‘e#d8d7ƒ‘e"d9d:ƒ‘e"d;d:ƒ‘e$d<d=ƒ‘e$d>d=ƒ‘e%d?d@ƒ‘e%dAd@ƒ‘e'dBdCƒ‘e'dDdCƒ‘edEdFƒ‘edGdFƒ‘edHdIƒ‘edJdIƒ‘edKdLƒ‘edMdLƒ‘edNdOƒ‘edPdOƒ‘e&dQdRƒ‘Z(G dSdT„ dTƒZ)dUeje de	fdVdW„Z*ej+dXfdYe	dZed[edefd\d]„Z,dS )_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                 C   s(   t  | ¡\}}t|d ƒ t j|||d�S )N)Ú	fillvalue)Ú	itertoolsÚteeÚnextÚzip_longest)r   ÚendÚleftÚright© r   úh/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/docstring_parser/numpydoc.pyÚ	_pairwise   s   
r   Ústringc                 C   s   |   ¡ } t| ƒdkr| S d S )Nr   )ÚstripÚlen)r   r   r   r   Ú
_clean_str   s   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                   @   sP   e Zd ZdZdededdfdd„Zedefdd	„ƒZd
edej	e
 fdd„ZdS )Ú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                 C   s   || _ || _d S ©N)r!   r"   )Úselfr!   r"   r   r   r   Ú__init__I   s   
zSection.__init__c                 C   s"   dt | jƒ }d| j› d|› d�S )z§Regular 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$   Údashesr   r   r   Útitle_patternM   s   zSection.title_patternÚtextc                 c   s   � t | jgt|ƒd�V  dS )zÁParse ``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)   r   r   r   ÚparseW   s   €zSection.parse)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr%   Úpropertyr(   ÚTÚIterabler   r+   r   r   r   r   r    ?   s    		r    c                   @   s>   e Zd ZdZdededefdd„Zdedeje fdd	„Z	d
S )Ú
_KVSectionzÚBase 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                 C   s   d S r#   r   ©r$   r"   r5   r   r   r   Ú_parse_itemk   s   z_KVSection._parse_itemr)   c                 c   s`   � t t |¡ƒD ]%\}}| ¡ }|d ur| ¡ nd }|||… }| j| ¡ t |¡d�V  qd S )N)r"   r5   )	r   ÚKV_REGEXÚfinditerr   Ústartr7   ÚgroupÚinspectÚcleandoc)r$   r)   ÚmatchÚ
next_matchr:   r   r5   r   r   r   r+   n   s   €
ÿüz_KVSection.parseN)
r,   r-   r.   r/   r0   r   r7   r2   r3   r+   r   r   r   r   r4   `   s    
r4   c                   @   s"   e Zd ZdZedefdd„ƒZdS )Ú_SphinxSectionz®Base parser for numpydoc sections with sphinx-style syntax.

    E.g. sections that look like this:
        .. title:: something
            possibly over multiple lines
    r   c                 C   s   d| j › d�S )Nz	^\.\.\s*(z)\s*::©r!   ©r$   r   r   r   r(   €   s   z_SphinxSection.title_patternN)r,   r-   r.   r/   r1   r0   r(   r   r   r   r   r@   x   s    r@   c                   @   ó&   e Zd ZdZdededefdd„ZdS )ÚParamSectionzíParser 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"   r5   r   c           
      C   sÜ   t  |¡}d  } } }}|d urG| d¡}| d¡}|d urGt |¡}|d ur0| d¡}d}nd}t |¡}	|	d urGd}|	 d¡}|	 d¡}t|ƒdkr_|d u r_t |¡}	|	d ur_|	 d¡}t| j	|gt
|ƒ||||d�S )NÚnameÚtypeTFr5   r   )Úargsr*   Úarg_nameÚ	type_nameÚis_optionalÚdefault)ÚPARAM_KEY_REGEXr>   r;   ÚPARAM_OPTIONAL_REGEXÚPARAM_DEFAULT_REGEXr   ÚPARAM_DEFAULT_REGEX_IN_DESCÚsearchr   r"   r   )
r$   r"   r5   r>   rH   rI   rJ   rK   Úoptional_matchÚdefault_matchr   r   r   r7   �   s8   









úzParamSection._parse_itemN)r,   r-   r.   r/   r0   r   r7   r   r   r   r   rD   …   s    
rD   c                   @   rC   )ÚRaisesSectionz¡Parser for numpydoc raises sections.

    E.g. any section that looks like this:
        ValueError
            A description of what might raise ValueError
    r"   r5   r   c                 C   s,   t | j|gt|ƒt|ƒdkr|d�S d d�S )Nr   )rG   r*   rI   )r	   r"   r   r   r6   r   r   r   r7   ½   s   ýýzRaisesSection._parse_itemN)r,   r-   r.   r/   r0   r	   r7   r   r   r   r   rS   µ   s    rS   c                   @   s*   e Zd ZdZdZdededefdd„ZdS )	ÚReturnsSectionzñParser 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"   r5   r   c                 C   sL   t  |¡}|d ur| d¡}| d¡}nd }d }t| jgt|ƒ|| j|d�S )NrE   rF   )rG   r*   rI   Úis_generatorÚreturn_name)ÚRETURN_KEY_REGEXr>   r;   r
   r"   r   rU   )r$   r"   r5   r>   rV   rI   r   r   r   r7   Ñ   s   

ûzReturnsSection._parse_itemN)r,   r-   r.   r/   rU   r0   r
   r7   r   r   r   r   rT   Å   s    	rT   c                   @   s   e Zd ZdZdZdS )ÚYieldsSectionz0Parser for numpydoc generator "yields" sections.TN)r,   r-   r.   r/   rU   r   r   r   r   rX   ã   s    rX   c                   @   ó(   e Zd ZdZdedeje fdd„ZdS )ÚDeprecationSectionz3Parser for numpydoc "deprecation warning" sections.r)   r   c                 c   sP   � |j ddd�d d g ^}}}|d urtt |¡ƒ}t| jg|t|ƒd�V  d S )NÚ
r   )ÚsepÚmaxsplit)rG   r*   Úversion)Úsplitr   r<   r=   r   r"   )r$   r)   r^   ÚdescÚ_r   r   r   r+   ì   s   €ÿzDeprecationSection.parseN)	r,   r-   r.   r/   r0   r2   r3   r   r+   r   r   r   r   rZ   é   s    rZ   c                   @   rY   )Ú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                 c   s¢   � t |ƒ ¡  ¡ }|rOg }g }|r#|d  d¡sn
| | d¡¡ |s|r7|d  d¡r-n
| | d¡¡ |s%t| jg|rBd |¡ndd |¡d�V  |sdS dS )zÄParse ``DocstringExample`` objects from the body of this section.

        :param text: section body text. Should be cleaned with
                     ``inspect.cleandoc`` before parsing.
        r   z>>>r[   N)Úsnippetr*   )	r   r   Ú
splitlinesÚ
startswithÚappendÚpopr   r"   Újoin)r$   r)   ÚlinesÚsnippet_linesÚdescription_linesr   r   r   r+     s*   €ýýýõzExamplesSection.parseN)	r,   r-   r.   r/   r0   r2   r3   r   r+   r   r   r   r   rb   ÷   s    rb   Ú
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                   @   s^   e Zd ZdZddejejeef  fdd„Z	dd„ Z
defd	d
„Zdeje defdd„ZdS )ÚNumpydocParserz%Parser for numpydoc-style docstrings.NÚsectionsc                 C   s$   |pt }dd„ |D ƒ| _|  ¡  dS )z[Setup sections.

        :param sections: Recognized sections or None to defaults.
        c                 S   s   i | ]}|j |“qS r   rA   ©Ú.0Úsr   r   r   Ú
<dictcomp>I  s    z+NumpydocParser.__init__.<locals>.<dictcomp>N)ÚDEFAULT_SECTIONSr–   Ú_setup)r$   r–   r   r   r   r%   C  s   zNumpydocParser.__init__c                 C   s,   t jd dd„ | j ¡ D ƒ¡t jd�| _d S )Nú|c                 s   s   � | ]}|j V  qd S r#   )r(   r—   r   r   r   Ú	<genexpr>N  s   € z(NumpydocParser._setup.<locals>.<genexpr>r   )ÚreÚcompilerh   r–   ÚvaluesÚMÚ	titles_rerB   r   r   r   rœ   L  s   þzNumpydocParser._setupÚsectionc                 C   s   || j |j< |  ¡  dS )zLAdd or replace a section.

        :param section: The new section.
        N)r–   r!   rœ   )r$   r¤   r   r   r   Úadd_sectionR  s   zNumpydocParser.add_sectionr)   r   c                 C   s$  t tjd�}|s
|S t |¡}| j |¡}|r(|d| ¡ … }|| ¡ d… }n|}d}| dd¡}|d p7d|_	t
|ƒdkrX|d pDd}| d¡|_| d¡|_| ¡ pVd|_t| j |¡ƒD ]/\}}tdd	„ | ¡ D ƒƒ}	| j|	 }
| ¡ }|dur€| ¡ nd}|j |
 |||… ¡¡ q`|S )
zaParse the numpy-style docstring into its components.

        :returns: parsed docstring
        )ÚstyleNÚ r[   r   r   z

c                 s   s   � | ]	}|d ur|V  qd S r#   r   )r˜   Úgr   r   r   rž   |  s   € z'NumpydocParser.parse.<locals>.<genexpr>)r   r   ÚNUMPYDOCr<   r=   r£   rP   r:   r_   Úshort_descriptionr   re   Úblank_after_short_descriptionÚendswithÚblank_after_long_descriptionr   Úlong_descriptionr   r9   r   Úgroupsr–   r   ÚmetaÚextendr+   )r$   r)   Úretr>   Ú
desc_chunkÚ
meta_chunkÚpartsÚlong_desc_chunkÚ	nextmatchr!   Úfactoryr:   r   r   r   r   r+   [  s4   
ÿ
zNumpydocParser.parser#   )r,   r-   r.   r/   r2   ÚOptionalÚDictr0   r    r%   rœ   r¥   r   r+   r   r   r   r   r•   @  s     		r•   r)   c                 C   s   t ƒ  | ¡S )zYParse the numpy-style docstring into its components.

    :returns: parsed docstring
    )r•   r+   )r)   r   r   r   r+   ˆ  s   r+   z    Ú	docstringÚrendering_styleÚindentc           
         sà  dt jtttf f‡ ‡fdd„‰dtdt jt j f‡‡fdd„}g ‰| jr+ˆ 	| j¡ | j
r3ˆ 	d¡ | jrbd	}| jjrE|d
| jj› �7 }| jjrP| jj ¡ }ng }dˆ › �}ˆ 	| |g| ¡¡ | jrkˆ 	| j¡ | jrsˆ 	d¡ |ddd„ | jp|g D ƒƒ |ddd„ | jp‰g D ƒƒ |ddd„ | jp–g D ƒƒ |ddd„ | jp£g D ƒƒ | jrÈ| jsÈ| j}ˆ 	|r¶dnd¡ ˆ 	dtˆd ƒ ¡ ˆ|ƒ |ddd„ | jpÑg D ƒƒ |ddd„ | jpÞg D ƒƒ |ddd„ | jpëg D ƒƒ |ddd„ | jpøg D ƒƒ t| jƒdk�r.ˆ 	d¡ ˆ 	d ¡ ˆ 	d!¡ | jD ]}|j�r"ˆ 	|j¡ |j�r,ˆ 	|j¡ �q| jD ]9}	t|	tttttfƒ�r@�q1ˆ 	d¡ ˆ 	|	jd  d"d¡ ¡ ¡ ˆ 	dt|	jd ƒ ¡ |	j�riˆ 	|	j¡ �q1d ˆ¡S )#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                    sÖ   t | tƒr	| j}nt | tƒr| j}nd }| jr"|r"|d| j› �7 }n| jr)| j}n|s-d}t | tƒrL| jdvr@|d| j› �7 }n| jsH| jdkrL|d7 }| jrddˆ › � 	|g| j 
¡  ¡}ˆ |¡ d S ˆ |¡ d S )Nz : r§   )NÚNonez
, default=r¿   z
, optionalr[   )Ú
isinstancer   rH   r
   rV   rI   rK   rJ   r*   rh   rd   rf   )r¾   ÚheadÚbody)r½   rµ   r   r   Úprocess_onež  s(   




zcompose.<locals>.process_onerE   rG   c                    sH   |r ˆ   d¡ ˆ   | ¡ ˆ   dtˆ d ƒ ¡ |D ]}ˆ|ƒ qd S d S )Nr§   r&   éÿÿÿÿ)rf   r   )rE   rG   Úarg)rµ   rÃ   r   r   Úprocess_sect¾  s   


ûzcompose.<locals>.process_sectr§   z.. deprecated::ú r[   rl   c                 S   ó   g | ]}|j d  dkr|‘qS )r   rm   ©rG   ©r˜   Úitemr   r   r   Ú
<listcomp>Þ  ó    zcompose.<locals>.<listcomp>r|   c                 S   rÈ   )r   r}   rÉ   rÊ   r   r   r   rÌ   ã  ó
    þr   c                 S   s   g | ]}|j s|‘qS r   ©rU   rÊ   r   r   r   rÌ   ì  s    ýÿr‚   c                 S   s   g | ]}|j r|‘qS r   rÏ   rÊ   r   r   r   rÌ   õ  s    r&   rÄ   rs   c                 S   rÈ   )r   rt   rÉ   rÊ   r   r   r   rÌ      rÎ   rq   c                 S   rÈ   )r   rr   rÉ   rÊ   r   r   r   rÌ   	  rÎ   rv   c                 S   rÈ   )r   rw   rÉ   rÊ   r   r   r   rÌ     rÍ   ry   c                 S   rÈ   )r   rz   rÉ   rÊ   r   r   r   rÌ     rÍ   r   r…   z--------ra   ) r2   ÚUnionr   r
   r	   r0   ÚListÚAnyrª   rf   r«   r”   r^   r*   rd   rh   r®   r­   ÚparamsÚmany_returnsr€   r   rw   r†   rc   r°   rÀ   r   r   rG   Úreplacer!   )
r»   r¼   r½   rÆ   ÚfirstÚrestr\   r²   Úexampler°   r   )r½   rµ   rÃ   r   Úcompose�  s¾   ÿ  


þþþ	þþ	þþþ	þþ	þþ



€
ûþ

€
rÙ   r#   )-r/   r<   r   rŸ   Útypingr2   Útextwrapr   Úcommonr   r   r   r   r   r	   r
   r   r   r3   r   r0   r¹   r   r    r¢   r8   rL   rM   rN   rO   rW   r    r4   r@   rD   rS   rT   rX   rZ   rb   r›   r•   r+   ÚCOMPACTrÙ   r   r   r   r   Ú<module>   sÐ    ,

	ÿÿ
!0&ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá#Hüþýüû