o
    /wiw                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm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 e	rVd dlmZ d dlmZ d dlmZ edZe
dZdZd(ddZd)ddZddd*d&d'ZdS )+    )annotations)wraps)	Parameter)	signature)Any)TYPE_CHECKING)TypeVarN)_validate_two_version)_validate_version)Callable)Sequence)	ParamSpec_P_Ta1  Positional arguments {deprecated_positional_arg_names} in {func_name}() have been deprecated since v{d_ver}. They will be replaced with the corresponding keyword arguments in v{r_ver}, so please use the keyword specification instead. See https://github.com/optuna/optuna/releases/tag/v{d_ver} for details.func'Callable[_P, _T]'return	list[str]c                 C  s    t | j}dd | D }|S )Nc                 S  s,   g | ]\}}|j tjkr|j|jkr|qS  )defaultr   emptykindPOSITIONAL_OR_KEYWORD).0namepr   r   \/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/optuna/_convert_positional_args.py
<listcomp>$   s
    z-_get_positional_arg_names.<locals>.<listcomp>)r   
parametersitems)r   paramspositional_arg_namesr   r   r   _get_positional_arg_names"   s
   
r"   previous_positional_arg_namesSequence[str]argsr   dict[str, Any]c                 G  s   dd t || D }|S )Nc                 S  s   i | ]\}}||qS r   r   )r   valarg_namer   r   r   
<dictcomp>-   s    z!_infer_kwargs.<locals>.<dictcomp>)zip)r#   r%   inferred_kwargsr   r   r   _infer_kwargs,   s   r,      )warning_stackleveldeprecated_versionstrremoved_versionr.   int0'Callable[[Callable[_P, _T]], Callable[_P, _T]]'c                   sb    dusdur% du rt ddu rt dt  t t  d	 fdd}|S )
a  Convert positional arguments to keyword arguments.

    Args:
        previous_positional_arg_names:
            List of names previously given as positional arguments.
        warning_stacklevel:
            Level of the stack trace where decorated function locates.
        deprecated_version:
            The version in which the use of positional arguments is deprecated.
        removed_version:
            The version in which the use of positional arguments will be removed.
    NzFdeprecated_version must not be None when removed_version is specified.zFremoved_version must not be None when deprecated_version is specified.r   r   r   c                   sZ   t t t jsJ t  dt t j t d	 fdd}|S )
Nz is not a subset of r%   r   kwargsr   '_T'c                    s  g }t }tg| R  }t|t|kr;t|t| }|j d| d  s.r;|tjj d |rHtj	d
|td t| tkrbtj dt dt|  dt||}t|rxtj d	| d
|| di |S )Nz() got zQ as positional arguments but they were expected to be given as keyword arguments.)deprecated_positional_arg_names	func_named_verr_ver
)
stacklevelz	() takes z positional arguments but z were given.z%() got multiple values for arguments .r   )r"   r,   lensetappend__name___DEPRECATION_WARNING_TEMPLATEformatwarningswarnjoinFutureWarning	TypeErrorintersectionupdate)r%   r4   warning_messagesr!   r+   expected_kwdsduplicated_kwds)r/   r   r#   r1   r.   r   r   converter_wrapperZ   sD   	
zOconvert_positional_args.<locals>.converter_decorator.<locals>.converter_wrapper)r%   r   r4   r   r   r5   )r>   issubsetr   r   r   )r   rM   r/   r#   r1   r.   )r   r   converter_decoratorS   s   
.z4convert_positional_args.<locals>.converter_decorator)r   r   r   r   )
ValueErrorr
   r	   )r#   r/   r1   r.   rP   r   rO   r   convert_positional_args1   s   
8rR   )r   r   r   r   )r#   r$   r%   r   r   r&   )
r#   r$   r/   r0   r1   r0   r.   r2   r   r3   )
__future__r   	functoolsr   inspectr   r   typingr   r   r   rC   optuna._deprecatedr	   optuna._experimentalr
   collections.abcr   r   typing_extensionsr   r   r   rA   r"   r,   rR   r   r   r   r   <module>   s,    
	


