o
    iz"                     @  s0  d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZ erHd dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ ejejejgZed Z	 ejdg dfejdg dfejdg dfiZG dd deddZdddddd.d'd(ZG d)d* d*eddZ dddddd/d,d-Z!dS )0    )annotationsN)TYPE_CHECKINGAnyLiteral	TypedDict)warn)Parser)GoogleOptions)DocstringSection)NumpyOptions)DocstringStyle)SphinxOptions)	Docstring)
heuristicsmax_sectionsz!\n[ \t]*{0}:([ \t]+.+)?\n[ \t]+.+)args	argumentsparams
parameterszkeyword argszkeyword argumentsz
other argszother argumentszother paramsother parametersraises
exceptionsreturnsyieldsreceivesexamples
attributes	functionsmethodsclassesmoduleswarnswarningsz\n[ \t]*{0}\n[ \t]*---+\n)
deprecatedr   r   r   r   r   r   r!   r   r   r   r   r    z&\n[ \t]*:{0}([ \t]+\w+)*:([ \t]+.+)?\n)param	parameterargargumentkeykeywordtypevarivarcvarvartyper   returnrtyper   raiseexcept	exceptionc                   @  s.   e Zd ZU dZded< 	 ded< 	 ded< dS )	PerStyleOptionsz(Per-style options for docstring parsing.r	   googler   numpyr   sphinxN__name__
__module____qualname____doc____annotations__ r>   r>   f/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/griffe/_internal/docstrings/auto.pyr4   j   s   
 r4   F)totalr   methodstyle_orderdefaultper_style_options	docstringr   rB   DocstringDetectionMethodrC   *list[Parser] | list[DocstringStyle] | NonerD   Parser | DocstringStyle | NonerE   PerStyleOptions | Noneoptionsr   r/   3tuple[Parser | None, list[DocstringSection] | None]c                  sT  ddl m} |r|rtdtdtdd |||d}n|s i }dd	 |p&tD }|d
kre|D ]"}t| \}fdd	|D }	t fdd|	D rQ|df  S q/|du s[t|t	r_|dfS t	|dfS |dkri }
|D ]}||  fi |
|i |
|< qmdd |
 D }t| }|D ]}|| |kr||
| f  S qtd| d)a"  Infer the parser to use for the docstring.

    The 'heuristics' method uses regular expressions. The 'max_sections' method
    parses the docstring with all parsers specified in `style_order` and returns
    the one who parsed the most sections.

    If heuristics fail, the `default` parser is returned. If multiple parsers
    parsed the same number of sections, `style_order` is used to decide which
    one to return. The `default` parser is never used with the 'max_sections' method.

    Additional options are parsed to the detected parser, if any.

    Parameters:
        docstring: The docstring to parse.
        method: The method to use to infer the parser.
        style_order: The order of the styles to try when inferring the parser.
        default: The default parser to use if the inference fails.
        per_style_options: Additional parsing options per style.
        **options: Deprecated. Use `per_style_options` instead.

    Returns:
        The inferred parser, and optionally parsed sections (when method is 'max_sections').
    r   )parsers2Cannot use both `options` and `per_style_options`.z;`**options` is deprecated. Use `per_style_options` instead.   
stacklevelr5   r6   r7   c                 S  s"   g | ]}t |trt|n|qS r>   )
isinstancestrr   ).0styler>   r>   r?   
<listcomp>   s   " z)infer_docstring_style.<locals>.<listcomp>r   c                   s&   g | ]}t  |t jt jB qS r>   )recompileformat
IGNORECASE	MULTILINE)rU   replacement)patternr>   r?   rW      s    c                 3  s    | ]	}|  jV  qd S )N)searchvalue)rU   r^   )rF   r>   r?   	<genexpr>   s    z(infer_docstring_style.<locals>.<genexpr>Nr   c                 S  s   i | ]	\}}|t |qS r>   )len)rU   rV   sectionr>   r>   r?   
<dictcomp>   s    z)infer_docstring_style.<locals>.<dictcomp>zInvalid method 'z'.)#griffe._internal.docstrings.parsersrM   
ValueErrorr   DeprecationWarning_default_style_order	_patternsanyrS   r   getitemsmaxvalues)rF   rB   rC   rD   rE   rK   rM   rV   replacementspatternsstyle_sectionsstyle_lengthsr   r>   )rF   r^   r?   infer_docstring_styleu   s<   !
&"rs   c                   @  s8   e Zd ZU dZded< 	 ded< 	 ded< 	 ded	< d
S )AutoOptionsz"Options for Auto-style docstrings.rG   rB   rH   rC   rI   rD   rJ   rE   Nr8   r>   r>   r>   r?   rt      s   
 rt   list[DocstringSection]c          	      K  s|   ddl m} |r|rtdtdtdd |||d}n|s i }t| ||||d\}}|d	u r<|| |fi ||i S |S )
au  Parse a docstring by automatically detecting the style it uses.

    See [`infer_docstring_style`][griffe.infer_docstring_style] for more information
    on the available parameters.

    Parameters:
        docstring: The docstring to parse.
        method: The method to use to infer the parser.
        style_order: The order of the styles to try when inferring the parser.
        default: The default parser to use if the inference fails.
        per_style_options: Additional parsing options per style.
        **options: Deprecated. Use `per_style_options` instead.

    Returns:
        A list of docstring sections.
    r   )parserN   z<`**options` are deprecated. Use `per_style_options` instead.rO   rP   rR   rA   N)re   rv   rf   r   rg   rs   rk   )	rF   rB   rC   rD   rE   rK   rv   rV   sectionsr>   r>   r?   
parse_auto   s$   
rx   )rF   r   rB   rG   rC   rH   rD   rI   rE   rJ   rK   r   r/   rL   )rF   r   rB   rG   rC   rH   rD   rI   rE   rJ   rK   r   r/   ru   )"
__future__r   rX   typingr   r   r   r   r"   r   griffe._internal.enumerationsr   "griffe._internal.docstrings.googler	   "griffe._internal.docstrings.modelsr
   !griffe._internal.docstrings.numpyr   re   r   "griffe._internal.docstrings.sphinxr   griffe._internal.modelsr   r7   r5   r6   rh   rG   ri   r4   rs   rt   rx   r>   r>   r>   r?   <module>   sP   JE