a
    h                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZmZ e	dddZ
dde	ee	 ee	 d	d
dZdde	ee	 dddZdS )    N)wraps)	Parameter	signature)IterableOptionalversionc                    s    fdd}|S )aB  Decorator for methods that issues warnings for positional arguments.
    Using the keyword-only argument syntax in pep 3102, arguments after the
    * will issue a warning when passed as a positional argument.

    Args:
        version (`str`):
            The version when positional arguments will result in error.
    c                    sr   t g g  j D ]6\}}|jtjkr: | q|jtjkr| qt fdd}|S )Nc               	      s   t | t   }|dkr&| i |S dd td | | | d  D }d|}tdj d| d dt |tj|  f i |S )	Nr   c                 S   s8   g | ]0\}}t |tr&| d | dn| d| qS )z=''=)
isinstancestr).0namearg r   ^/var/www/html/assistant/venv/lib/python3.9/site-packages/huggingface_hub/utils/_deprecation.py
<listcomp>!   s   zi_deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f.<locals>.<listcomp>, z+Deprecated positional argument(s) used in 'z': pass z as keyword args. From version z? passing these as positional arguments will result in an error,)	lenzipjoinwarningswarn__name__FutureWarningupdate
parameters)argskwargs
extra_argsZargs_msg)all_argsfkwonly_argssigr   r   r   inner_f   s"    

zU_deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f)	r   r   itemskindr   POSITIONAL_OR_KEYWORDappendKEYWORD_ONLYr   )r!   r   paramr$   r   )r    r!   r"   r#   r    _inner_deprecate_positional_args   s    zD_deprecate_positional_args.<locals>._inner_deprecate_positional_argsr   )r   r+   r   r   r   _deprecate_positional_args   s    
 r,   )custom_message)r   deprecated_argsr-   c                    s    fdd}|S )a  Decorator to issue warnings when using deprecated arguments.

    TODO: could be useful to be able to set a custom error message.

    Args:
        version (`str`):
            The version when deprecated arguments will result in error.
        deprecated_args (`List[str]`):
            List of the arguments to be deprecated.
        custom_message (`str`, *optional*):
            Warning message that is raised. If not passed, a default warning message
            will be created.
    c                    s(   t  t  fdd}|S )Nc                     s   g }t | j D ]\}}|jv r||j q| D ]*\}}|v r<|j| jkr<|| q<t|dkrdj dd	| d d} d ur|d  7 }t
|t | i |S )Nr   z Deprecated argument(s) used in 'z': r   z&. Will not be supported from version ''.z

)r   r   valuesr   r(   r%   defaultr   r   r   r   r   r   )r   r   Zused_deprecated_args_Z	parameterZ
kwarg_nameZkwarg_valuemessage)r-   r.   r!   r#   r   r   r   r$   K   s*    

zO_deprecate_arguments.<locals>._inner_deprecate_positional_args.<locals>.inner_f)r   r   r!   r$   r-   r.   r   )r!   r#   r   r+   H   s    z>_deprecate_arguments.<locals>._inner_deprecate_positional_argsr   )r   r.   r-   r+   r   r5   r   _deprecate_arguments4   s    !r6   )r3   )r   r3   c                    s    fdd}|S )aC  Decorator to issue warnings when using a deprecated method.

    Args:
        version (`str`):
            The version when deprecated arguments will result in error.
        message (`str`, *optional*):
            Warning message that is raised. If not passed, a default warning message
            will be created.
    c                    s<    j dkr jdd t  fdd}|S )N__init__.r   c                     sH   d d j  d d}d ur.|d 7 }t|t  | i |S )Nr	   z	' (from 'z3') is deprecated and will be removed from version 'r/    )
__module__r   r   r   )r   r   Zwarning_message)r!   r3   r   r   r   r   r$   |   s    zC_deprecate_method.<locals>._inner_deprecate_method.<locals>.inner_f)r   __qualname__splitr   r4   r3   r   )r!   r   r   _inner_deprecate_methodw   s    	z2_deprecate_method.<locals>._inner_deprecate_methodr   )r   r3   r>   r   r=   r   _deprecate_methodl   s    r?   )r   	functoolsr   inspectr   r   typingr   r   r   r,   r6   r?   r   r   r   r   <module>   s   18