o
    ;i                     @   s\   d dl Z d dlZd dlZd dlZd dlZd dlmZ deeef fddZ	defddZ
dS )    N)FunctionWithAioreturnc                 C   s   t | }t|}dtfdd}t|}tt|d }t	|tj
tjfs*J dd |jD }t|j|jfg| }tdd |jD }|j|||d |d	 |d |d	 d	  fS )
a3  Get function signature, including decorators and comments, from source code

    Traverses functools.wraps-wrappings to get source of underlying function.

    Has the advantage over inspect.signature that it can get decorators, default arguments and comments verbatim
    from the function definition.
    r   c                 S   sL   |  d}||d | }|d d | |d< |d |d  |d< d|S )N
   r   )splitjoin)srcfromlinefromcoltolinetocollines r   N/home/ubuntu/.local/lib/python3.10/site-packages/modal_docs/mdmd/signatures.pyget_source_segment   s
   

z/_signature_from_ast.<locals>.get_source_segmentr   c                 S   s   g | ]
}|j |jd  fqS )r   lineno
col_offset.0itemr   r   r   
<listcomp>    s    z'_signature_from_ast.<locals>.<listcomp>c                 s   s    | ]	}|j |jfV  qd S )Nr   r   r   r   r   	<genexpr>"   s    z&_signature_from_ast.<locals>.<genexpr>r   )inspect	getsourcetextwrapdedentstrastparselistiter_child_nodes
isinstanceFunctionDefAsyncFunctionDefdecorator_listminr   r   bodynamestrip)funcr	   r   treefunc_defdecorator_startsdeclaration_start
body_startr   r   r   _signature_from_ast   s   


&r1   c                 C   s   t |st |st|tst|dsJ |j}zt|\}}W n ty?   t	
d|  d | }d|  t | }Y nw || krP|d| d|  }d|v rpt |spt |sp|dd}|dd}|d	d
}tdd|\}}|S )a  A problem with using *only* this method is that the wrapping method signature will not be respected.
    TODO: use source parsing *only* to extract default arguments, comments (and possibly decorators) and "merge"
          that definition with the outer-most definition.__call__z#Could not get source signature for z. Using fallback.zdef z	async defdefasynccontextmanagercontextmanagerAsyncIteratorIteratorz^\s*@synchronizer\..*\n )r   
isfunctionismethodr#   r   hasattrr2   r1   	Exceptionwarningswarn	signaturereplaceiscoroutinefunctionisasyncgenfunctionresubn)r)   callableoriginal_namedefinition_source_r   r   r   get_signature*   s,   rI   )r   r   rC   r   r=   synchronicity.synchronizerr   tupler   r1   rI   r   r   r   r   <module>   s   