
    Dj                     >    d dl mZ d dlmZ dgZ G d de      Zd Zy)    )
attrgetter)update_wrapperif_has_delegatec                       e Zd ZdZd ZddZy)_IffHasDelegateas  Implements a conditional property using the descriptor protocol.
    Using this class to create a decorator will raise an ``AttributeError``
    if none of the delegates (specified in ``delegate_names``) is an attribute
    of the base object or the first found delegate does not have an attribute
    ``attribute_name``.

    This allows ducktyping of the decorated method based on
    ``delegate.attribute_name``. Here ``delegate`` is the first item in
    ``delegate_names`` for which ``hasattr(object, delegate) is True``.

    See https://docs.python.org/3/howto/descriptor.html for an explanation of
    descriptors.
    c                 8    || _         || _        t        | |       y N)fndelegate_namesr   )selfr
   r   s      aC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/utils/metaestimators.py__init__z_IffHasDelegate.__init__   s    , 	tR     Nc                      B j                   D ]  }	  t        |              n  t         j                   d                 fd}t        | j                         |S # t        $ r Y _w xY w)Nc                  0     j                   g| i |S r	   )r
   )argskwargsobjr   s     r   <lambda>z)_IffHasDelegate.__get__.<locals>.<lambda>5   s    wtwws'DT'DV'D r   )r   r   AttributeErrorr   r
   )r   r   typedelegate_nameouts   ``   r   __get__z_IffHasDelegate.__get__%   s    ? "&!4!4 9-J}-c2 9 4
4..r23C8 EsDGG$
 & s   A%%	A10A1r	   )__name__
__module____qualname____doc__r   r    r   r   r   r      s    !r   r   c                 j     t         t              rt                t         t              s f  fdS )a  Wrap a delegated instance attribute function.

    Creates a decorator for methods that are delegated in the presence of a
    results wrapper. This enables duck-typing by ``hasattr`` returning True
    according to the sub-estimator.

    This function was adapted from scikit-learn, which defines
    ``if_delegate_has_method``, but operates differently by injecting methods
    not based on method presence, but by delegate presence.

    Examples
    --------
    >>> from pmdarima.utils.metaestimators import if_has_delegate
    >>>
    >>> class A(object):
    ...     @if_has_delegate('d')
    ...     def func(self):
    ...         return True
    >>>
    >>> a = A()
    >>> # the delegate does not exist yet
    >>> assert not hasattr(a, 'func')
    >>> # inject the attribute
    >>> a.d = None
    >>> assert hasattr(a, 'func') and a.func()

    Parameters
    ----------
    delegate : string, list of strings or tuple of strings
        Name of the sub-estimator that can be accessed as an attribute of the
        base object. If a list or a tuple of names are provided, the first
        sub-estimator that is an attribute of the base object will be used.
    c                     t        |       S r	   )r   )r
   delegates    r   r   z!if_has_delegate.<locals>.<lambda>b   s    ob(3 r   )
isinstancelisttuple)r#   s   `r   r   r   ;   s0    D (D!?h&;33r   N)operatorr   	functoolsr   __all__objectr   r   r    r   r   <module>r+      s+      $ 
(f (V'4r   