o
    i                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZ d dlZd dlmZmZ d dlmZ ddlmZ edZd#ddZd#ddZd$ddZd%ddZd&ddZd'd!d"ZdS )(    )annotationsN)Any	AwaitableCallableOptionalTypeTypeVar)InputTOutputT)WorkflowRunOperationContext   )WorkflowHandleServiceHandlerTstartdCallable[[ServiceHandlerT, WorkflowRunOperationContext, InputT], Awaitable[WorkflowHandle[OutputT]]]return6tuple[Optional[Type[InputT]], Optional[Type[OutputT]]]c              
   C  s   t | \}}t|}|sd}nt|ts#td| j d|  d}|rVt|}t	|dkrS|r7d| nd}td| d| j d	t	| | d
 d}||fS |\}||fS )zReturn operation input and output types.

    `start` must be a type-annotated start method that returns a
    :py:class:`temporalio.nexus.WorkflowHandle`.
    NzExpected return type of z, to be a subclass of WorkflowHandle, but is r   :  zExpected return type z of z- to have exactly one type parameter, but has .)
3_get_start_method_input_and_output_type_annotationstyping
get_origin
issubclassr   warningswarn__name__get_argslen)r   
input_typeoutput_typeorigin_typeargssuffix r$   \/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/nexus/_util.py?get_workflow_run_start_method_input_and_output_type_annotations   s4   



r&   c                 C  s   zt | }W n ty   td|  d Y dS w |dd }t|dkrF|r.d| nd}td|  dt| | d	 d }||fS | \}}t|t	s_td
|  d| d	 d }||fS )Nz Expected decorated start method z to have type annotationsNNr      r   r   zI to have exactly 2 type-annotated parameters (ctx and input), but it has r   zExpected first parameter of z: to be an instance of WorkflowRunOperationContext, but is )
r   get_type_hints	TypeErrorr   r   popr   valuesr   r   )r   type_annotationsr    r#   r   ctx_typer$   r$   r%   r   F   s:   	


r   fnCallable[..., Any]strc                 C  sB   t | dd}|st| rt| dr| jj}|std|  d|S )z%Return the name of a callable object.r   N__call__z,Could not determine callable name: expected z' to be a function or callable instance.)getattrcallablehasattr	__class__r   r*   )r/   method_namer$   r$   r%   get_callable_namel   s   r8   objr   Mtuple[Optional[Callable[[Any], Any]], Optional[nexusrpc.Operation[Any, Any]]]c                 C  sF   t | }|r
| }nt| dd }rt |}t|t jsdS ||fS )zReturn the :py:class:`Operation` for the object along with the factory function.

    ``obj`` should be a decorated operation start method.
    __nexus_operation_factory__Nr'   )nexusrpcget_operation_definitionr3   
isinstance	Operation)r9   op_defnfactoryr$   r$   r%   get_operation_factoryz   s   


rB   operation_factoryCallable[[Any], Any]Nonec                 C  s   t | d| dS )ztSet the :py:class:`OperationHandler` factory for this object.

    ``obj`` should be an operation start method.
    r;   N)setattr)r9   rC   r$   r$   r%   set_operation_factory   s   rG   boolc                 C  sB   t | tjr| j} t | tjst| p t| o tt| ddS )ziReturn True if `obj` is an async callable.

    Supports partials of async callable class instances.
    r2   N)r>   	functoolspartialfuncinspectiscoroutinefunctionr4   r3   )r9   r$   r$   r%   is_async_callable   s   
rN   )r   r   r   r   )r/   r0   r   r1   )r9   r   r   r:   )r9   r   rC   rD   r   rE   )r9   r   r   rH   )
__future__r   rI   rL   r   r   r   r   r   r   r   r   r<   r	   r
   #temporalio.nexus._operation_contextr   _tokenr   r   r&   r   r8   rB   rG   rN   r$   r$   r$   r%   <module>   s"     	

'
&

