o
    e                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZmZ de	fddZ
ddde	d	ee	 d
ee	 fddZddde	dee	 f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 ]\}}|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|  d	i |S )
Nr   c                 S   s8   g | ]\}}t |tr| d | dn| d| qS )z=''=)
isinstancestr).0namearg r   RD:\Projects\ConvertPro\env\Lib\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,r   )	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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 r3|j| jkr3|| qt|dkrZdj dd	| d d} d urT|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   r6   r   _deprecate_arguments4   s   !r7   )r4   r4   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   t   fdd}|S )Nc                     sJ   d j  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 'r0    )r   
__module__r   r   r   )r   r   Zwarning_message)r!   r4   r   r   r   r$   x   s   zC_deprecate_method.<locals>._inner_deprecate_method.<locals>.inner_fr   r5   r4   r   )r!   r   _inner_deprecate_methodw   s   	z2_deprecate_method.<locals>._inner_deprecate_methodr   )r   r4   r;   r   r:   r   _deprecate_methodl   s   r<   )r   	functoolsr   inspectr   r   typingr   r   r   r-   r7   r<   r   r   r   r   <module>   s    1
 8