o
    .i|                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZ ddlm	Z	 e
 ae	eZddee fddZG d	d
 d
e jZG dd de jedZdS )    N)wraps)CallableOptional   )
get_loggerhelp_messagec                    s   dt f fdd}|S )zDecorator to mark a class or a function as deprecated.

    Args:
        help_message (:obj:`str`, optional): An optional message to guide the user on how to
            switch to non-deprecated usage of the library.
    deprecated_class_or_functionc                    s   t | r| j | j}n|   j}|dkr|n jdd }r+| dd  ndt  fdd}d	|_t | rE|| _| S |S )
N__init__.zI is deprecated and will be removed in the next major version of datasets.  c                     s8   t  }|tvrtjtdd t|  | i |S )N   )category
stacklevel)hash_emitted_deprecation_warningswarningswarnFutureWarningadd)argskwargs	func_hashdeprecated_functionwarning_msg T/home/ubuntu/.local/lib/python3.10/site-packages/datasets/utils/deprecation_utils.pywrapper(   s
   
z.deprecated.<locals>.decorator.<locals>.wrapper
deprecated)inspectisclassr	   __name____qualname__splitr   _decorator_name_)r   namer   r   r   r   	decorator   s"   

zdeprecated.<locals>.decorator)r   )r   r)   r   r(   r   r       s   "r    c                       sF   e Zd ZdZ fddZ fddZdddddd fd	d
Z  ZS )OnAccessz\
    Enum metaclass that calls a user-specified function whenever a member is accessed.
    c                    s*   t  |}t|tjr|jr|  |S N)super__getattribute__
isinstanceenumEnum
_on_access)clsr'   obj	__class__r   r   r-   @   s   zOnAccess.__getattribute__c                    s   t  |}|jr|  |S r+   )r,   __getitem__r1   )r2   r'   memberr4   r   r   r6   F   s   zOnAccess.__getitem__Nr   modulequalnametypestartc                   s6   t  j||||||d}t|tjr|jr|  |S )Nr8   )r,   __call__r.   r/   r0   r1   )r2   valuenamesr9   r:   r;   r<   r3   r4   r   r   r=   L   s   zOnAccess.__call__r+   )r#   
__module__r$   __doc__r-   r6   r=   __classcell__r   r   r4   r   r*   ;   s
    "r*   c                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	DeprecatedEnumzQ
    Enum class that calls `deprecate` method whenever a member is accessed.
    c                 C   s   t | }||_|j|_|S r+   )object__new___value_	deprecater1   )r2   r>   r7   r   r   r   rE   X   s   
zDeprecatedEnum.__new__c                 C   s   dS )Nr   r   )selfr   r   r   r   ^   s   zDeprecatedEnum.help_messagec                 C   s:   | j r	d| j  nd}tjd| jj d| tdd d S )Nr   r   'zJ' is deprecated and will be removed in the next major version of datasets.   )r   )r   r   r   __objclass__r#   r   )rH   r   r   r   r   rG   b   s   
zDeprecatedEnum.deprecateN)r#   r@   r$   rA   rE   propertyr   rG   r   r   r   r   rC   S   s    
rC   )	metaclassr+   )r/   r!   r   	functoolsr   typingr   r   loggingr   setr   r#   loggerstrr    EnumMetar*   r0   rC   r   r   r   r   <module>   s    -