
    %`i              	          d dl Z d dlZd dl mZ d dlmZmZmZmZ d dlm	Z	  ej
        e          ZdZdede j        fdZdded
edee         fdZdee         deedf         deeef         ddfdZdee         deedf         deeef         dee         fdZdee         deee         eeef         f         fdZdS )    N)	Parameter)AnyDictListTuple)	is_cythons   __RAY_DUMMY__funcreturnc           	           t                     r[g d}t           fd|D                       r* }d  |D ]!}t           |t          ||                     "nt	           d          t          j                   S )aB  Get signature parameters.

    Support Cython functions by grabbing relevant attributes from the Cython
    function and attaching to a no-op function. This is somewhat brittle, since
    inspect may change, but given that inspect is written to a PEP, we hope
    it is relatively stable. Future versions of Python may allow overloading
    the inspect 'isfunction' and 'ismethod' functions / create ABC for Python
    functions. Until then, it appears that Cython won't do anything about
    compatability with the inspect module.

    Args:
        func: The function whose signature should be checked.

    Returns:
        A function signature object, which includes the names of the keyword
            arguments as well as their default values.

    Raises:
        TypeError: A type error if the signature is not supported
    )__code____annotations____defaults____kwdefaults__c              3   8   K   | ]}t          |          V  d S N)hasattr).0attrr	   s     i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_common/signature.py	<genexpr>z get_signature.<locals>.<genexpr>,   s-      55twtT""555555    c                      d S r    r   r   r   r	   zget_signature.<locals>.func/   s    r   z( is not a Python function we can process)r   allsetattrgetattr	TypeErrorinspect	signature)r	   attrsoriginal_funcr   s   `   r   get_signaturer"      s    .  QQQQ5555u55555 		Q M    B BdGM4$@$@AAAAB tOOOPPPT"""r   Fignore_firstc                     t          t          |           j                                                  }|r5t	          |          dk    rt          d| j         d          |dd         }|S )a\  Extract the function signature from the function.

    Args:
        func: The function whose signature should be extracted.
        ignore_first: True if the first argument should be ignored. This should
            be used when func is a method of a class.

    Returns:
        List of Parameter objects representing the function signature.
    r   z5Methods must take a 'self' argument, but the method 'z' does not have one.   N)listr"   
parametersvalueslen
ValueError__name__)r	   r#   signature_parameterss      r   extract_signaturer-   :   s      d 3 3 > E E G GHH 8#$$))?=? ? ?    4ABB7r   r,   args.kwargsc                     t          j        |           }	  |j        |i | dS # t          $ r"}t          t	          |                    dd}~ww xY w)a  Validates the arguments against the signature.

    Args:
        signature_parameters: The list of Parameter objects
            representing the function signature, obtained from
            `extract_signature`.
        args: The positional arguments passed into the function.
        kwargs: The keyword arguments passed into the function.

    Raises:
        TypeError: Raised if arguments do not fit in the function signature.
    )r'   N)r   	Signaturebindr   str)r,   r.   r/   reconstructed_signatureexcs        r   validate_argsr6   R   sr     &/;OPPP,$$d5f55555 , , ,C!!t+,s   & 
AAAc                     t          | ||           g }|D ]}|t          |gz  }|                                D ]\  }}|||gz  }|S )a  Validates the arguments against the signature and flattens them.

    The flat list representation is a serializable format for arguments.
    Since the flatbuffer representation of function arguments is a list, we
    combine both keyword arguments and positional arguments. We represent
    this with two entries per argument value - [DUMMY_TYPE, x] for positional
    arguments and [KEY, VALUE] for keyword arguments. See the below example.
    See `recover_args` for logic restoring the flat list back to args/kwargs.

    Args:
        signature_parameters: The list of Parameter objects
            representing the function signature, obtained from
            `extract_signature`.
        args: The positional arguments passed into the function.
        kwargs: The keyword arguments passed into the function.

    Returns:
        List of args and kwargs. Non-keyword arguments are prefixed
            by internal enum DUMMY_TYPE.

    Raises:
        TypeError: Raised if arguments do not fit in the function signature.
    )r6   
DUMMY_TYPEitems)r,   r.   r/   	list_argsargkeywords         r   flatten_argsr=   h   sm    4 &f555I ' 'j#&&		 $ $gs^#		r   flattened_argsc                    t          |           dz  dk    s
J d            g }i }t          dt          |           d          D ];}| |         | |dz            }}|t          k    r|                    |           6|||<   <||fS )aD  Recreates `args` and `kwargs` from the flattened arg list.

    Args:
        flattened_args: List of args and kwargs. This should be the output of
            `flatten_args`.

    Returns:
        args: The non-keyword arguments passed into the function.
        kwargs: The keyword arguments passed into the function.
       r   zAFlattened arguments need to be even-numbered. See `flatten_args`.r%   )r)   ranger8   append)r>   r.   r/   
name_indexnamer;   s         r   recover_argsrE      s     	Na1$$$J 	%$$DFAs>22A66  
":.zA~0Nc:KKF4LL<r   )F)r   loggingr   typingr   r   r   r   ray._private.inspect_utilr   	getLoggerr+   loggerr8   r1   r"   boolr-   r3   r6   r=   rE   r   r   r   <module>rL      s           ) ) ) ) ) ) ) ) ) ) ) ) / / / / / /
 
	8	$	$ 
%# %# 1 %# %# %# %#P   C  t  Y        0,y/,16sCx,JNsTWx.,	, , , ,,!y/!16sCx!JNsTWx.!	#Y! ! ! !Hc uT#YS#X5N/O      r   