o
    Xij                     @  s`   d Z ddlmZ ddlZddlZddlZddlmZ dd	d
ZdddZ	dddZ
dddZdS )z'Utilities for working with Python ASTs.    )annotationsN)Callablefuncr   returntuple[str, ast.FunctionDef]c             
   C  s   zt | }W n ty } z
td| j d|d }~ww t|}t|}t	|tj
s0J t|jdks9J |jd }t	|tjsFJ ||fS )Nz@Decorator script does not work on dynamically compiled function .   r   )inspect	getsourceOSErrorRuntimeError__name__textwrapdedentastparse
isinstanceModulelenbodyFunctionDef)r   srcetop_level_astf_ast r   R/home/ubuntu/.local/lib/python3.10/site-packages/onnxscript/_internal/ast_utils.pyget_src_and_ast   s"   


r   exprast.Subscriptc                 C  s   | j }t|tjr|jS |gS )N)slicer   r   Tupleelts)r   
index_exprr   r   r   normalize_subscript_expr   s   r$   stmtast.stmtboolc                 C  s<   t | tjrt | jtjrt | jjtjr| jjjdkS dS )z=Return True if the statement is a call to the print function.printF)r   r   ExprvalueCallr   Nameidr%   r   r   r   is_print_call)   s
   r/   c                 C  s,   t | tjrt | jtjrt | jjtS dS )z,Return True if the statement is a docstring.F)r   r   r)   r*   Constantstrr.   r   r   r   is_doc_string2   s   r2   )r   r   r   r   )r   r   )r%   r&   r   r'   )__doc__
__future__r   r   r	   r   typingr   r   r$   r/   r2   r   r   r   r   <module>   s   


	