
    Vhh	                        d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZ erd dlmZmZ ddZdddZej"                  dd       Zdd	Z	 	 	 	 	 	 	 	 dd
Zy)    )annotationsN)AnyCallableTYPE_CHECKING)_infra	formatter)MappingSequencec           	         | j                   }t        j                  t        j                  | j                  | j
                  || j                  |            S )z:Returns a StackFrame for the given traceback.FrameSummary.)urilinesnippetfunctionmessage)location)r   r   
StackFrameLocationfilenamelinenoname)framer   s     \/home/dcms/DCMS/lib/python3.12/site-packages/torch/onnx/_internal/diagnostics/infra/utils.pypython_framer      sE    jjGZZ
     c                $   | dk  rt        d      |dk  rt        d      | dz  } t        j                         }t        j                  | |z         }|j                          || d D cg c]  }t        |       c}|_        d|_        |S c c}w )z&Returns the current Python call stack.r   z#frames_to_skip must be non-negativez"frames_to_log must be non-negative   )limitNzPython call stack)	
ValueErrorr   Stack	tracebackextract_stackreverser   framesr   )frames_to_skipframes_to_logstackr#   r   s        r   python_call_stackr'      s    >??q=>>aNLLNE$$>M+IJF
NN5;NO5LMEL'MEL'EML Ns   *Bc                b    t        j                  |       \  }}||t        j                  |       fS )zReturns the source lines, line number, and source file path for the given function.

    Essentially, inspect.getsourcelines() and inspect.getsourcefile() combined.
    Caching is applied to reduce the performance impact of this function.
    )inspectgetsourcelinesgetsourcefile)fnsource_linesr   s      r   _function_source_infor.   .   s1     #11"5L&!6!6r!:::r   c                    t        |       \  }}}t        |      dkD  r|d   j                         nd}t        j                  |||t        j                  |             S )z*Returns a Location for the given function.r   z	<unknown>)r   r   r   r   )r.   lenstripr   r   r   display_name)r,   r-   r   r   r   s        r   function_locationr3   9   s[     5b 9L&#),\):Q)>l1o##%KG??&&r*	 r   c                d     t        j                  |       j                  |i |}|j                  S )N)r)   	signaturebind	arguments)r,   argskwargsr6   s       r   function_stater:   E   s0     &7R %%t6v6D>>r   )r   ztraceback.FrameSummaryreturnz_infra.StackFrame)r      )r$   intr%   r=   r;   z_infra.Stack)r,   r   r;   z%tuple[Sequence[str], int, str | None])r,   r   r;   z_infra.Location)r,   r   r8   ztuple[Any, ...]r9   zdict[str, Any]r;   zMapping[str, Any])
__future__r   	functoolsr)   r    typingr   r   r   &torch.onnx._internal.diagnostics.infrar   r   collections.abcr	   r
   r   r'   	lru_cacher.   r3   r:    r   r   <module>rE      sp    "    / / D 1  ; ;	'1?r   