o
    Rh                     @   s  d dl Z d dlmZ d dlmZ d dlZd dlmZmZ d dl	m
Z
mZmZ edZdd Zd	d
 Zd&ddZd'dee defddZejde dd Zejde dd Zedkrd dlZd dlZejddZejddd e Ze ej!Z"ej!#dZ$e%e$dkre &de$d  re$d! Z'ndZ'e(ee"d" e'e"d"< e"d" ree"ej!d#Z)e*e) e+d$ dS e*d%,ej! dS dS )(    N)	signature)Optional)enable_halving_search_cvenable_iterative_imputer)all_displaysall_estimatorsall_functionsznumpydoc.validatec                  c   s    t  } t }| | D ]@\}}|drqg }t|D ]}|dr#qt||}t|ds2t|tr7|| q|d  t	|t
dD ]}||fV  qCqd S )N___call__)key)r   r   
startswithdirgetattrhasattr
isinstancepropertyappendsortedstr)
estimatorsdisplaysnameKlassmethods
method_objmethod r   _/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/sklearn/tests/test_docstrings.pyget_all_methods   s&   




r   c                  c   s8    t  } | D ]\}}d|jvr|j d|j V  qd S )Nzutils.fixes.)r   
__module____name__)	functionsr	   funcr   r   r   get_all_functions_names%   s   
r$   c                 c   sh    | D ].\}}|dv rq|dv r#|dur#|dur#t ||}t|tr#q|dur,|dv r,q||fV  qdS )za
    Ignore some errors based on the method type.

    These rules are specific for scikit-learn.)RT02GL01GL02)PR02GL08N)EX01SA01ES01)r   r   r   )errorsr   r   codemessager   r   r   r   filter_errors-   s   


r0   r   returnc                 C   s   |du rt |drd}n
|du rtdt|dur;t||}ztt|}W n ty2   d}Y nw |jd | }nd}|}ddt| d || | d	 d
ddd | d D g }|S )a~  Pretty print original docstring and the obtained errors

    Parameters
    ----------
    res : dict
        result of numpydoc.validate.validate
    Klass : {Estimator, Display, None}
        estimator object or None
    method : str
        if estimator is not None, either the method name or None.

    Returns
    -------
    str
       String representation of the error.
    N__init__z0At least one of Klass, method should be providedzM
Parsing of the method signature failed, possibly because this is a property.r    z

file	docstringz# Errors
c                 s   s     | ]\}}d  ||V  qdS )z	 - {}: {}N)format).0r.   r/   r   r   r   	<genexpr>   s    
zrepr_errors.<locals>.<genexpr>r-   )	r   
ValueErrorNotImplementedErrorr   r   r   	TypeErrorr!   join)resr   r   objobj_signatureobj_namemsgr   r   r   repr_errorsZ   s8   



rC   function_namec                 C   sH   t | }tt|d dd|d< |d r"t|d|  d}t|dS )z)Check function docstrings using numpydoc.r-   functionr   zTested function: N)numpydoc_validationvalidatelistr0   rC   r:   )rD   requestr>   rB   r   r   r   test_function_docstring   s   
rK   zKlass, methodc                 C   sp   | j }|| jg}|d ur|| d|}t|}tt|d || d|d< |d r6t|| |}t	|d S )Nr   r-   )r   )
r    r!   r   r=   rG   rH   rI   r0   rC   r:   )r   r   rJ   base_import_pathimport_pathr>   rB   r   r   r   test_docstring   s   



rN   __main__z!Validate docstring with numpydoc.)descriptionrM   zImport path to validate)helpr      z(?:[A-Z][a-z]*)+r-   rF      z#All docstring checks passed for {}!)N)NN)-reinspectr   typingr   pytestsklearn.experimentalr   r   sklearn.utils.discoveryr   r   r   importorskiprG   r   r$   r0   r   rC   markparametrizerK   rN   r!   argparsesysArgumentParserparseradd_argument
parse_argsargsrH   rM   r>   splitimport_path_sectionslenmatchr   rI   rB   printexitr7   r   r   r   r   <module>   sF    

-7


