U
    ½mœd‘
  ã                   @   s>   d dl mZ d dlmZ d dlmZ G dd„ dƒZdd„ ZdS )	é    )Ú
MethodType)Úwraps)Úupdate_wrapperc                   @   s"   e Zd Z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
   úT/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/utils/_available_if.pyÚ__init__   s    z_AvailableIfDescriptor.__init__Nc                    s`   t dt|jƒ› dtˆjƒ› �ƒ‰ |d k	rDˆ |¡s6ˆ ‚tˆj|ƒ}ntˆjƒ‡ ‡fdd„ƒ}|S )NzThis z has no attribute c                     s   ˆ  | d ¡sˆ ‚ˆj| |ŽS )Nr   )r   r   )ÚargsÚkwargs©Zattr_errr	   r
   r   Úout'   s    z+_AvailableIfDescriptor.__get__.<locals>.out)ÚAttributeErrorÚreprÚ__name__r   r   r   r   r   )r	   ÚobjÚownerr   r
   r   r   Ú__get__   s    ÿ
z_AvailableIfDescriptor.__get__)N)r   Ú
__module__Ú__qualname__Ú__doc__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>W   ó    zavailable_if.<locals>.<lambda>r
   r   r
   r   r   Úavailable_if0   s    'r   N)Útypesr   Ú	functoolsr   r   r   r   r
   r
   r
   r   Ú<module>   s   *