
    sg                         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	e
      Z	 	 	 	 	 dd
ededee   dedededee   fdZy)    N)wraps)Optional   )__version__   )ExplicitEnumc                       e Zd ZdZdZdZdZy)Actionnonenotifynotify_alwaysraiseN)__name__
__module____qualname__NONENOTIFYNOTIFY_ALWAYSRAISE     Q/var/www/html/venv/lib/python3.12/site-packages/transformers/utils/deprecation.pyr
   r
      s    DF#MEr   r
   old_nameversionnew_name warn_if_greater_or_equal_version!raise_if_greater_or_equal_versionraise_if_both_namesadditional_messagec                     
 t         j                  j                  |      }t         j                  j                  t              }||k\  

rd| nd| 
 f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                      t        j                         }t        |j                  j	                               }d|v d|v t                	
fd       }|S )Nselfclsc                     j                   }	r| d   j                  j                    d| }nr| d   j                    d| }t        j                  }d }|v rV
|v rRrt        j                  nt        j
                  }d d
 d| d
 d|
    d d|    d	}|j                         n^|v r:
8
|vr4t        j                  }d
 d d| d
 d	}|j                        |
<   n |v rt        j                  }d
 d d| d	}|	| d }rKr$|t        j                  k7  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        | 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_nameminimum_actionmessager   funcis_class_methodis_greater_or_equal_versionis_instance_methodr   r   r   r   version_messager   s        r   wrapped_funcz6deprecate_kwarg.<locals>.wrapper.<locals>.wrapped_funcr   s1    I!#Aw0099:!I;G	 #Aw//0)=	#[[NG 6!h&&81D&J^J^"8*GH:_YKWabjakklmst|m}l~  Z  [c  Zd  de  fl  mu  fv  ew  wy  z

8$ V#(<QWAW!'hZ'77HykYabjakkuv#)::h#7x  V#!'hZ'77HykY[\"'9'E$IQ'9&:; + 56;;9V%+\\N :nPVP]P]>]%+[[N - ))FMM63G3G#HHg}C(((r   )inspect	signatureset
parameterskeysr   )r5   sigfunction_named_argsr:   r6   r8   r   r7   r   r   r   r   r9   r   s   `   @@r   wrapperz deprecate_kwarg.<locals>.wrapperk   sf    %!#.."5"5"78#'::#66	t2	) 2	) 
2	)h r   )	packagingr   parser   )r   r   r   r   r   r   r   deprecated_versioncurrent_versionrB   r7   r9   s   ` `````   @@r   deprecate_kwargrG       sl    D #**009''--k:O"15G"G">wiH;G9E< <| Nr   )NFFFN)r;   r-   	functoolsr   typingr   packaging.versionrC    r   r   r
   strboolrG   r   r   r   <module>rN      s          \  #-2.3 %(,III smI '+	I
 (,I I !Ir   