o
    ¦ôj¾  ã                   @   s–   d dl Z d dlZd dlmZ d dlmZ d dlZddlm	Z	 ddlm
Z
 G dd	„ d	e
ƒZ		
	
	
	ddededee dedededee fdd„ZdS )é    N)Úwraps)ÚOptionalé   )Ú__version__é   )ÚExplicitEnumc                   @   s   e Zd ZdZdZdZdZdS )ÚActionÚnoneÚnotifyZnotify_alwaysÚraiseN)Ú__name__Ú
__module__Ú__qualname__ÚNONEÚNOTIFYÚNOTIFY_ALWAYSÚRAISE© r   r   úo/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/transformers/utils/deprecation.pyr      s
    r   FÚold_nameÚversionÚnew_nameÚ warn_if_greater_or_equal_versionÚ!raise_if_greater_or_equal_versionÚraise_if_both_namesÚadditional_messagec           
         sX   t j |¡}t j t¡}||k‰ˆrd|› �‰nd|› �‰‡ ‡‡‡‡‡‡‡fdd„}	|	S )aÒ
  
    Function or method decorator to notify users about deprecated keyword arguments, replacing them with a new name if specified.

    This decorator allows you to:
    - Notify users when a keyword argument is deprecated.
    - Automatically replace deprecated keyword arguments with new ones.
    - Raise an error if deprecated arguments are used, depending on the specified conditions.

    By default, the decorator notifies the user about the deprecated argument while the `transformers.__version__` < specified `version`
    in the decorator. To keep notifications with any version `warn_if_greater_or_equal_version=True` can be set.

    Parameters:
        old_name (`str`):
            Name of the deprecated keyword argument.
        version (`str`):
            The version in which the keyword argument was (or will be) deprecated.
        new_name (`Optional[str]`, *optional*):
            The new name for the deprecated keyword argument. If specified, the deprecated keyword argument will be replaced with this new name.
        warn_if_greater_or_equal_version (`bool`, *optional*, defaults to `False`):
            Whether to show warning if current `transformers` version is greater or equal to the deprecated version.
        raise_if_greater_or_equal_version (`bool`, *optional*, defaults to `False`):
            Whether to raise `ValueError` if current `transformers` version is greater or equal to the deprecated version.
        raise_if_both_names (`bool`, *optional*, defaults to `False`):
            Whether to raise `ValueError` if both deprecated and new keyword arguments are set.
        additional_message (`Optional[str]`, *optional*):
            An additional message to append to the default deprecation message.

    Raises:
        ValueError:
            If raise_if_greater_or_equal_version is True and the current version is greater than or equal to the deprecated version, or if raise_if_both_names is True and both old and new keyword arguments are provided.

    Returns:
        Callable:
            A wrapped function that handles the deprecated keyword arguments according to the specified parameters.

    Example usage with renaming argument:

        ```python
        @deprecate_kwarg("reduce_labels", new_name="do_reduce_labels", version="6.0.0")
        def my_function(do_reduce_labels):
            print(do_reduce_labels)

        my_function(reduce_labels=True)  # Will show a deprecation warning and use do_reduce_labels=True
        ```

    Example usage without renaming argument:

        ```python
        @deprecate_kwarg("max_size", version="6.0.0")
        def my_function(max_size):
            print(max_size)

        my_function(max_size=1333)  # Will show a deprecation warning
        ```

    z"and removed starting from version zand will be removed in version c                    sT   t  ˆ ¡}t|j ¡ ƒ}d|v ‰d|v ‰tˆ ƒ‡‡ ‡‡‡‡‡‡‡‡	‡
fdd„ƒ}|S )NÚselfÚclsc                     s¦  ˆj }ˆr| d jj › d|› �}nˆr| d j › d|› �}tj}d }ˆ|v rTˆ|v rTˆr/tjntj}dˆ› dˆ› d|› dˆ› d|ˆ › dˆ› d|ˆ › d	�}| ˆ¡ n9ˆ|v rzˆd urzˆ|vrztj}d
ˆ› dˆ	› d|› dˆ› d�	}| ˆ¡|ˆ< nˆ|v r�tj}d
ˆ› dˆ	› d|› d	�}|d urœˆ d urœ|› dˆ › �}ˆr³ˆr©|tjkr©tj}n
ˆ
s³|tjkr³tj}|tjkr¼t|ƒ‚|tjtjfv rÌt	j
|tdd� ˆ| i |¤ŽS )Nr   Ú.zBoth `z` and `z` are set for `z
`. Using `ú=z` and ignoring deprecated `z`.ú`z` is deprecated z for `z`. Use `z
` instead.ú r   )Ú
stacklevel)r   Ú	__class__r   r   r   r   Úpopr   Ú
ValueErrorÚwarningsÚwarnÚFutureWarning)ÚargsÚkwargsÚ	func_nameZminimum_actionÚmessage)r   ÚfuncÚis_class_methodÚis_greater_or_equal_versionÚis_instance_methodr   r   r   r   Úversion_messager   r   r   Úwrapped_funcr   s<   8
z6deprecate_kwarg.<locals>.wrapper.<locals>.wrapped_func)ÚinspectÚ	signatureÚsetÚ
parametersÚkeysr   )r-   ÚsigÚfunction_named_argsr2   ©r   r/   r   r   r   r   r1   r   )r-   r.   r0   r   Úwrapperk   s   
"4z deprecate_kwarg.<locals>.wrapper)Ú	packagingr   Úparser   )
r   r   r   r   r   r   r   Zdeprecated_versionZcurrent_versionr;   r   r:   r   Údeprecate_kwarg    s   B
>r>   )NFFFN)r3   r&   Ú	functoolsr   Útypingr   Úpackaging.versionr<   Ú r   r   r   ÚstrÚboolr>   r   r   r   r   Ú<module>   s8   
ùÿþýüûúù