a
    h                     @   s6   d dl mZmZ d dlmZ G dd dZdd ZdS )    )update_wrapperwraps)
MethodTypec                   @   s*   e Zd ZdZdd Zdd Zd	ddZdS )
_AvailableIfDescriptorav  Implements a conditional property using the descriptor protocol.

    Using this class to create a decorator will raise an ``AttributeError``
    if check(self) returns a falsey value. Note that if check raises an error
    this will also result in hasattr returning false.

    See https://docs.python.org/3/howto/descriptor.html for an explanation of
    descriptors.
    c                 C   s    || _ || _|| _t| | d S )N)fncheckattribute_namer   )selfr   r   r    r
   W/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/utils/_available_if.py__init__   s    z_AvailableIfDescriptor.__init__c              
   C   sj   dt |j dt | j }z| |}W n. tyX } zt||W Y d }~n
d }~0 0 |sft|d S )NzThis z has no attribute )repr__name__r   r   	ExceptionAttributeError)r	   objownerZattr_err_msgZcheck_resulter
   r
   r   _check   s     z_AvailableIfDescriptor._checkNc                    s@   |d ur$j | d tj|}ntj fdd}|S )Nr   c                     s"   j | d  d j| i |S )Nr   r   )r   r   )argskwargsr   r	   r
   r   out1   s    z+_AvailableIfDescriptor.__get__.<locals>.out)r   r   r   r   )r	   r   r   r   r
   r   r   __get__'   s    z_AvailableIfDescriptor.__get__)N)r   
__module____qualname____doc__r   r   r   r
   r
   r
   r   r      s   
r   c                    s    fddS )a  An attribute that is available only if check returns a truthy value.

    Parameters
    ----------
    check : callable
        When passed the object with the decorated method, this should return
        a truthy value if the attribute is available, and either return False
        or raise an AttributeError if not available.

    Returns
    -------
    callable
        Callable makes the decorated method available if `check` returns
        a truthy value, otherwise the decorated method is unavailable.

    Examples
    --------
    >>> from sklearn.utils.metaestimators import available_if
    >>> class HelloIfEven:
    ...    def __init__(self, x):
    ...        self.x = x
    ...
    ...    def _x_is_even(self):
    ...        return self.x % 2 == 0
    ...
    ...    @available_if(_x_is_even)
    ...    def say_hello(self):
    ...        print("Hello")
    ...
    >>> obj = HelloIfEven(1)
    >>> hasattr(obj, "say_hello")
    False
    >>> obj.x = 2
    >>> hasattr(obj, "say_hello")
    True
    >>> obj.say_hello()
    Hello
    c                    s   t |  | jdS )N)r   )r   r   )r   r   r
   r   <lambda>`       zavailable_if.<locals>.<lambda>r
   r   r
   r   r   available_if9   s    'r!   N)	functoolsr   r   typesr   r   r!   r
   r
   r
   r   <module>   s   1