U
    9%e                     @   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&ee ed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r4e &de$d r4e$d  Z'ndZ'e(ee"d! e'e"d!< e"d! rzee"ej!d"Z)e*e) e+d# ne*d$,ej! 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 ]8}|drDq4t||}t|dsbt|tr4|| q4|d  t	|t
dD ]}||fV  qqd S )N___call__)key)r   r   
startswithdirgetattrhasattr
isinstancepropertyappendsortedstr)Z
estimatorsZdisplaysnameKlassmethods
method_objmethod r   \/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sklearn/tests/test_docstrings.pyget_all_methods   s    



r   c                  c   s6   t  } | D ]&\}}d|jkr
|j d|j V  q
d S )Nzutils.fixes.)r   
__module____name__)Z	functionsr	   funcr   r   r   get_all_functions_names%   s    
r!   c                 c   sf   | D ]\\}}|dkrq|dkrD|dk	rD|dk	rDt ||}t|trDq|dk	rV|dkrVq||fV  qdS )za
    Ignore some errors based on the method type.

    These rules are specific for scikit-learn.)ZRT02ZGL01ZGL02)ZPR02ZGL08N)ZEX01ZSA01ZES01)r   r   r   )errorsr   r   codemessager   r   r   r   filter_errors-   s    


r%   )r   returnc                 C   s   |dkr.t |drd}n|dkr*tdnt|dk	rzt||}ztt|}W n tk
rh   d}Y nX |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

fileZ	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   objZobj_signatureobj_namemsgr   r   r   repr_errorsZ   s6    




r6   function_namec                 C   sH   t | }tt|d dd|d< |d rDt|d|  d}t|dS )z)Check function docstrings using numpydoc.r"   functionr   zTested function: N)numpydoc_validationvalidatelistr%   r6   r.   )r7   requestr2   r5   r   r   r   test_function_docstring   s
    
r>   zKlass, methodc                 C   sp   | j }|| jg}|d k	r"|| d|}t|}tt|d || d|d< |d rlt|| |}t	|d S )Nr   r"   )r   )
r   r   r   r1   r:   r;   r<   r%   r6   r.   )r   r   r=   Zbase_import_pathimport_pathr2   r5   r   r   r   test_docstring   s    



r@   __main__z!Validate docstring with numpydoc.)descriptionr?   zImport path to validate)helpr      z(?:[A-Z][a-z]*)+r"   r9      z#All docstring checks passed for {}!)N)NN)-reinspectr   typingr   ZpytestZsklearn.experimentalr   r   Zsklearn.utils.discoveryr   r   r   Zimportorskipr:   r   r!   r%   r   r6   markZparametrizer>   r@   r   argparsesysArgumentParserparseradd_argument
parse_argsargsr;   r?   r2   splitZimport_path_sectionslenmatchr   r<   r5   printexitr+   r   r   r   r   <module>   sD   

-7


 

