
    BVh.                         d Z ddlmZ ddlZddlZddlmZmZmZm	Z	  e	d      Z
 G d dee
         Z G d d	ee
         Zy)
zJA simple stack that associates filename and line numbers with each object.    )IteratorN)castGenericOptionalTypeVarTc                   Z    e Zd ZdZd\  ZZZ	 	 ddedee	   dee
   fdZdde
d	e
fd
Zd Zy)TraceableObjectz>Wrap an object together with its the code definition location.)r         Nobjfilenamelinenoc                 .    || _         || _        || _        y N)r   r   r   )selfr   r   r   s       [/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/traceable_stack.py__init__zTraceableObject.__init__    s     DHDMDK    offsetreturnc                    | j                   }t        j                         }|s| j                  S t	        t
        j                  |      }t        |dz         D ]:  }|j                  }|| j                  } nt	        t
        j                  |      }|}< |j                  j                  | _        t	        t        |j                        | _        |S )aZ  Set filename and line using the caller's stack frame.

    If the requested stack information is not available, a heuristic may
    be applied and self.HEURISTIC USED will be returned.  If the heuristic
    fails then no change will be made to the filename and lineno members
    (None by default) and self.FAILURE will be returned.

    Args:
      offset: Integer.  If 0, the caller's stack frame is used.  If 1,
          the caller's caller's stack frame is used.  Larger values are
          permissible but if out-of-range (larger than the number of stack
          frames available) the outermost stack frame will be used.

    Returns:
      TraceableObject.SUCCESS if appropriate stack information was found,
      TraceableObject.HEURISTIC_USED if the offset was larger than the stack,
      and TraceableObject.FAILURE if the stack was empty.
    r   )SUCCESSinspectcurrentframeFAILUREr   types	FrameTyperangef_backHEURISTIC_USEDf_codeco_filenamer   intf_linenor   )r   r   retcodeframe_parents         r   !set_filename_and_line_from_callerz1TraceableObject.set_filename_and_line_from_caller*   s    & llG  "E\\%(E 6A: ||f	%%EOOV,fe LL,,DMsENN+DKNr   c                 R    | j                  d| j                  | j                        S )z?Return a TraceableObject like this one, but without the object.N)r   r   )	__class__r   r   r   s    r   copy_metadatazTraceableObject.copy_metadataP   s    >>$t{{>KKr   )NNr   )__name__
__module____qualname____doc__r   r!   r   r   r   strr$   r   r*   r.    r   r   r
   r
      s^    F &/"'>7
 !%"	  sm	$c $# $LLr   r
   c                       e Zd ZdZ	 ddeeee         fdZddede	fdZ
defd	Zdefd
Zdee   fdZdeee      fdZde	fdZddZy)TraceableStackzA stack of TraceableObjects.Nexisting_stackc                 ,    |r|dd | _         yg | _         y)zConstructor.

    Args:
      existing_stack: [TraceableObject, ...] If provided, this object will
        set its new stack to a SHALLOW COPY of existing_stack.
    N)_stack)r   r8   s     r   r   zTraceableStack.__init__X   s     CQ^A->DK24 	Kr   r   r   c                 v    t        |      }| j                  j                  |       |j                  |dz         S )a  Add object to the stack and record its filename and line information.

    Args:
      obj: An object to store on the stack.
      offset: Integer.  If 0, the caller's stack frame is used.  If 1,
          the caller's caller's stack frame is used.

    Returns:
      TraceableObject.SUCCESS if appropriate stack information was found,
      TraceableObject.HEURISTIC_USED if the stack was smaller than expected,
      and TraceableObject.FAILURE if the stack was empty.
    r   )r
   r:   appendr*   )r   r   r   traceable_objs       r   push_objzTraceableStack.push_objd   s7     $C(MKK}% ::6A:FFr   r   c                 J    | j                   j                         j                  S )zFRemove last-inserted object and return it, without filename/line info.)r:   popr   r-   s    r   pop_objzTraceableStack.pop_objw   s    ;;??   r   c                 4    | j                   d   j                  S )z%Return the most recent stored object.)r:   r   r-   s    r   peek_top_objzTraceableStack.peek_top_obj{   s    ;;r?r   c                 :    d t        | j                        D        S )z=Return iterator over stored objects ordered newest to oldest.c              3   4   K   | ]  }|j                     y wr   )r   ).0t_objs     r   	<genexpr>z+TraceableStack.peek_objs.<locals>.<genexpr>   s     9%EII9s   reversedr:   r-   s    r   	peek_objszTraceableStack.peek_objs   s    98DKK#899r   c                 ,    t        | j                        S )zFReturn iterator over stored TraceableObjects ordered newest to oldest.rJ   r-   s    r   peek_traceable_objsz"TraceableStack.peek_traceable_objs   s    DKK  r   c                 ,    t        | j                        S )zFReturn number of items on the stack, and used for truth-value testing.)lenr:   r-   s    r   __len__zTraceableStack.__len__   s    t{{r   c                 ,    t        | j                        S )zReturn a copy of self referencing the same objects but in a new list.

    This method is implemented to support thread-local stacks.

    Returns:
      TraceableStack with a new list that holds existing objects.
    )r7   r:   r-   s    r   copyzTraceableStack.copy   s     $++&&r   r   r/   )r   zTraceableStack[T])r0   r1   r2   r3   r   listr
   r   r   r$   r>   rA   rD   r   rL   rN   rQ   rS   r5   r   r   r7   r7   U   s    $ BF
6$T/!*<%=>
6G! GS G&!q !A :! :!8OA,>#? !s 'r   r7   )r3   collections.abcr   r   r   typingr   r   r   r   r   r
   r7   r5   r   r   <module>rW      sF    Q $   3 3CL8Lgaj 8Lv>'WQZ >'r   