a
    
d                      @   s   d dl Z d dlmZ d dlmZmZ d dlmZ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e
dddZedddZeeeg eee  ZG dd deZG dd deedZdS )    Nwraps)	Parameter	signature)	Generator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   k/var/www/html/stable-diffusion-webui/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/   r0   r#   r%   r
   r   r   r&   M   s*    

zO_deprecate_arguments.<locals>._inner_deprecate_positional_args.<locals>.inner_f)r   r   r#   r&   r/   r0   r
   )r#   r%   r   r-   J   s    z>_deprecate_arguments.<locals>._inner_deprecate_positional_argsr   )r
   r0   r/   r-   r   r7   r   _deprecate_arguments6   s    !r8   )r5   )r
   r5   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r0|d 7 }t|t  | i |S )Nr   z	' (from 'z3') is deprecated and will be removed from version 'r1    )r   
__module__r   r   r   )r   r    warning_message)r#   r5   r
   r   r   r&   z   s    zC_deprecate_method.<locals>._inner_deprecate_method.<locals>.inner_fr   r6   r5   r
   r#   r   _inner_deprecate_methody   s    	z2_deprecate_method.<locals>._inner_deprecate_methodr   )r
   r5   r>   r   r<   r   _deprecate_methodn   s    r?   c                    s    fdd}|S )a  Decorator to deprecate the usage as a list of the output of a method.

    To be used when a method currently returns a list of objects but is planned to return
    an generator instead in the future. Output is still a list but tweaked to issue a
    warning message when it is specifically used as a list (e.g. get/set/del item, get
    length,...).

    Args:
        version (`str`):
            The version when output will start to be an generator.
    c                    s   t   fdd}|S )Nc                     s&    | i |}t |dj dddS )Na'  '{f.__name__}' currently returns a list of objects but is planned to be a generator starting from version {version} in order to implement pagination. Please avoid to use `{f.__name__}(...).{attr_name}` or explicitly convert the output to a list first with `[item for item in {f.__name__}(...)]`.z{attr_name})r#   r
   	attr_namer;   )DeprecatedListformat)r   r    Z
list_value)r#   r
   r   r   r&      s    zH_deprecate_list_output.<locals>._inner_deprecate_method.<locals>.inner_fr   r6   r	   r=   r   r>      s    z7_deprecate_list_output.<locals>._inner_deprecate_methodr   )r
   r>   r   r	   r   _deprecate_list_output   s    rD   )returnc                   c   s   d S Nr   r   r   r   r   
_empty_gen   s    rG   c                       s    e Zd ZdZ fddZ  ZS )DeprecateListMetaclasszFMetaclass that overwrites all list-only methods, including magic ones.c                    sX   d|vrt dt|vr t ddd }tD ]}|tt||||< q,t | |||S )N
_deprecatezJA `_deprecate` method must be implemented to use `DeprecateListMetaclass`.z?Class must inherit from `list` to use `DeprecateListMetaclass`.c                    s   t   fdd}|S )Nc                    s    |    | g|R i |S rF   )rI   )selfr   r    r#   r   r   r   _inner   s    
zIDeprecateListMetaclass.__new__.<locals>._with_deprecation.<locals>._innerr   )r#   r   rL   r   rK   r   _with_deprecation   s    z9DeprecateListMetaclass.__new__.<locals>._with_deprecation)	TypeErrorlist_LIST_ONLY_ATTRSgetattrsuper__new__)clsZclsnamebasesattrsrM   attr	__class__r   r   rS      s    	zDeprecateListMetaclass.__new__)r   r:   __qualname____doc__rS   __classcell__r   r   rX   r   rH      s   rH   c                       s6   e Zd ZdZed fddZeddddZ  ZS )	rB   zCustom List class for which all calls to a list-specific method is deprecated.

    Methods that are shared with a generator are not deprecated.
    See `_deprecate_list_output` for more details.
    rA   c                    s   t  | || _dS )zInitialize the list with a default warning message.

        Warning message will be formatted at runtime with a "{attr_name}" value.
        N)rR   __init___deprecation_msg)rJ   iterabler;   rX   r   r   r]      s    zDeprecatedList.__init__N)r@   rE   c                 C   s   t | jj|dt d S )N)r@   )r   r   r^   rC   r   )rJ   r@   r   r   r   rI      s    zDeprecatedList._deprecate)r   r:   rZ   r[   r   r]   rI   r\   r   r   rX   r   rB      s   rB   )	metaclass)r   	functoolsr   inspectr   r   typingr   r   r   r   r.   r8   r?   rD   rG   	frozensetsetdirrP   typerH   rO   rB   r   r   r   r   <module>   s    38'