
    0Ph                     B    d dl mZmZ d dlmZ  G d d          Zd ZdS )    )update_wrapperwraps)
MethodTypec                   &    e Zd ZdZd Zd Z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                 P    || _         || _        || _        t          | |           d S N)fncheckattribute_namer   )selfr
   r   r   s       [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/_available_if.py__init__z_AvailableIfDescriptor.__init__   s0    
, 	tR         c                     dt          |j                   dt          | j                   }	 |                     |          }n"# t          $ r}t          |          |d }~ww xY w|st          |          d S )NzThis z has no attribute )repr__name__r   r   	ExceptionAttributeError)r   objownerattr_err_msgcheck_resultes         r   _checkz_AvailableIfDescriptor._check   s    WD((WWDAT<U<UWW 		6::c??LL 	6 	6 	6 ..A5	6  	/ ...	/ 	/s   A 
A#AA#Nc                      |-                      |           t           j        |          }n t           j                   fd            }|S )Nr   c                  X                         | d                     j        | i |S )Nr   r   )r   r
   )argskwargsr   r   s     r   outz+_AvailableIfDescriptor.__get__.<locals>.out1   s4    DG5111tw////r   )r   r   r
   r   )r   r   r   r!   s   ` ` r   __get__z_AvailableIfDescriptor.__get__'   sm    ? KK5K)))TWc**CC
 47^^0 0 0 0 0 ^0 
r   r	   )r   
__module____qualname____doc__r   r   r"    r   r   r   r      sP         ! ! !
/ 
/ 
/     r   r   c                       f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                 2    t          | | j                  S )N)r   )r   r   )r
   r   s    r   <lambda>zavailable_if.<locals>.<lambda>`   s    ,Rr{SSS r   r&   )r   s   `r   available_ifr*   9   s    N TSSSSr   N)	functoolsr   r   typesr   r   r*   r&   r   r   <module>r-      sx    , + + + + + + +      . . . . . . . .b'T 'T 'T 'T 'Tr   