
    6bi7                        S r SSKrSSKrSSKrSSKJs  Jr  \	" \S5      (       a  \R                  r
O\R                  " S/ SQ5      r
\	" \S5      (       a  \R                  rO\R                  " S/ SQ5      rS r\	" \S5      (       a  \R                  rS	 rO\R"                  rS
 rS rS rS rS rS rS rS rS rS#S jrS rS rS rS rS rS rS rS r S r!S r"S r#S r$S  r%S! r&S$S" jr'g)%z6TFDecorator-aware replacements for the inspect module.    NArgSpecargsvarargskeywordsdefaultsFullArgSpecr   r   varkwr   
kwonlyargskwonlydefaultsannotationsc           
          [        U [        5      (       a  U $ [        U R                  U R                  U R                  U R
                  / S 0 S9$ )Nr
   )
isinstancer	   r   r   r   r   )argspecs    W/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/utils/tf_inspect.py%_convert_maybe_argspec_to_fullargspecr   4   sJ    ';''\\!!     getfullargspecc                     [        U 5      n[        UR                  UR                  UR                  UR
                  S9nU$ )ap  A python3 version of getargspec.

Calls `getfullargspec` and assigns args, varargs,
varkw, and defaults to a python 2/3 compatible `ArgSpec`.

The parameter name 'varkw' is changed to 'keywords' to fit the
`ArgSpec` struct.

Args:
  target: the target object to inspect.

Returns:
  An ArgSpec with args, varargs, keywords, and defaults parameters
  from FullArgSpec.
r   )r   r   r   r   r   r   )targetfullargspecsargspecss      r   _getargspecr   E   sC      &f-"" ((!''!**	
 r   c                 *    [        [        U 5      5      $ )zA python2 version of getfullargspec.

Args:
  target: the target object to inspect.

Returns:
  A FullArgSpec with empty kwonlyargs, kwonlydefaults and annotations.
)r   
getargspec)r   s    r   _getfullargspecr   a   s     5Z5GHHr   c                  8    [         R                  " 5       S   S   $ )z7TFDecorator-aware replacement for inspect.currentframe.   r   _inspectstack r   r   currentframer$   m   s    >>Aq!!r   c                    [        U [        R                  5      (       a  [        U 5      $ [        R
                  R                  R                  U 5      u  p[        S U 5       S5      nU(       a  U$  [        U5      $ ! [         a     Of = f[        U[        5      (       aL   [        UR                  5      $ ! [         a     Of = f [        UR                  5      $ ! [         a     Of = f[        [        U5      R                  5      $ )a0  TFDecorator-aware replacement for `inspect.getargspec`.

Note: `getfullargspec` is recommended as the python 2/3 compatible
replacement for this function.

Args:
  obj: A function, partial function, or callable object, possibly decorated.

Returns:
  The `ArgSpec` that describes the signature of the outermost decorator that
  changes the callable's signature, or the `ArgSpec` that describes
  the object if not decorated.

Raises:
  ValueError: When callable's signature can not be expressed with
    ArgSpec.
  TypeError: For objects of unsupported types.
c              3   X   #    U  H   nUR                   c  M  UR                   v   M"     g 7fN)decorator_argspec).0ds     r   	<genexpr>getargspec.<locals>.<genexpr>   s(      	
""  As   **N)r   	functoolspartial_get_argspec_for_partialtf__internal__	decoratorunwrapnextr   	TypeErrortype__init____new____call__)obj
decoratorsr   specs       r   r   r   r   s    & #y(())',,2299#>J	
	

 	D 6""  &$	v// 			v~~.. 		
 tF|,,--s6   3
A> >
B
B$B9 9
CC
C 
C,+C,c           
        ^ [        U R                  5      nU R                  =(       d    0 n[        U R                  5      u  p4pVX1S n[        5       mT/[        U5      -  nU(       a  Xg[        U5      * S& UR                  5        H3  u  pX;   a  UR                  U5      n
XU
'   M!  U(       a  M*  [        S5      e   [        U4S j[        U5       5       S5      nUc  [        X4US5      $ [        U5       VVs/ s H  u  pUTL d  M  X:  d  M  X<   PM     nnnU(       a  [        SU S35      e[        X4U[        X{S 5      5      $ s  snnf )zImplements `getargspec` for `functools.partial` objects.

Args:
  obj: The `functools.partial` object
Returns:
  An `inspect.ArgSpec`
Raises:
  ValueError: When callable's signature can not be expressed with
    ArgSpec.
NzSFunction does not have **kwargs parameter, but contains an unknown partial keyword.c              3   :   >#    U  H  u  pUTLd  M  Uv   M     g 7fr'   r#   )r)   idxx
no_defaults      r   r+   +_get_argspec_for_partial.<locals>.<genexpr>   s     J2az6I2s   	zSome arguments z| do not have default value, but they are positioned after those with default values. This can not be expressed with ArgSpec.)lenr   r   r   funcobjectitemsindex
ValueErrorr4   	enumerater   tuple)r:   n_prune_argspartial_keywordsr   r   r   r   all_defaultskwdefaultr?   first_defaultijinvalid_default_valuesrA   s                  @r   r/   r/      sn   T sxx=L||)r(2388(<%D8 D
 J<#d)+L)1c(m^%& (--/:**R.C '7  0 J9\2JDM
 th55
 l++DA
? 	 0 	+   45 6F F
 	
 4(E,~2N,OPPs   :E		E	E	c                     [         R                  R                  R                  U 5      u  pU H'  nUR                  c  M  [        UR                  5      s  $    [        U5      $ )a  TFDecorator-aware replacement for `inspect.getfullargspec`.

This wrapper emulates `inspect.getfullargspec` in[^)]* Python2.

Args:
  obj: A callable, possibly decorated.

Returns:
  The `FullArgSpec` that describes the signature of
  the outermost decorator that changes the callable's signature. If the
  callable is not decorated, `inspect.getfullargspec()` will be called
  directly on the callable.
)r0   r1   r2   r3   r(   r   r   )r:   r;   r   r*   s       r   r   r     sU     2299#>J*89L9LMM  6""r   c                     U S   nU SS n[        U5      nUR                  5       n[        USS5      =(       d    [        USS5      n[        U5      (       a  U(       a  U4U-   nUR                   Vs/ s H  owU;  d  M
  UPM     nnUR                  [        [        X5      5      5        UR                  (       d  SO[        UR                  5      n	U	(       a8  [        UR                  U	* S UR                  5       H  u  pzXu;  d  M  XU'   M     UR                  b.  UR                  R                  5        H  u  pX;  d  M  XU'   M     U$ s  snf )aB  TFDecorator-aware replacement for inspect.getcallargs.

Args:
  *func_and_positional: A callable, possibly decorated, followed by any
    positional arguments that would be passed to `func`.
  **named: The named argument dictionary that would be passed to `func`.

Returns:
  A dictionary mapping `func`'s named arguments to the values they would
  receive if `func(*positional, **named)` were called.

`getcallargs` will use the argspec from the outermost decorator that
provides it. If no attached decorators modify argspec, the final unwrapped
target's argspec will be used.
r   r   Nim_self__self__)r   copygetattrismethodr   updatedictzipr   rC   r   rF   )func_and_positionalnamedrD   
positionalr   	call_argsthisargremaining_positionalsdefault_countvaluekvs                r   getcallargsri   !  s6     q!D$QR(JT"G

I4D)LWT:t-LD~~$Wz)
||#)';|   T#3@AB$--A3w7G7G3HMgllM>?;W=M=MNJC#!&# O )**002DA! ! 3 s   2	E?Ec                  .    [         R                  " U 0 UD6$ r'   )r!   getframeinfo)r   kwargss     r   rk   rk   H  s      $1&11r   c                 .    [         R                  " U 5      $ )a  TFDecorator-aware replacement for inspect.getdoc.

Args:
  obj: An object, possibly decorated.

Returns:
  The docstring associated with the object.

The outermost-decorated object is intended to have the most complete
documentation, so the decorated parameter is not unwrapped.
)r!   getdocr:   s    r   rn   rn   L  s     ??3r   c                     [         R                  R                  R                  U 5      S   n[	        US5      (       a  SUR
                  ;   a  UR
                  S   $ [        R                  " U5      $ )z2TFDecorator-aware replacement for inspect.getfile.r   	f_globals__file__)r0   r1   r2   r3   hasattrrq   r!   getfile)r:   unwrapped_objects     r   rt   rt   [  sd    0077<Q? 	 +..*444))*55,--r   c                 .    [         R                  " X5      $ )z5TFDecorator-aware replacement for inspect.getmembers.)r!   
getmembers)r:   	predicates     r   rw   rw   k  s    s..r   c                 .    [         R                  " U 5      $ )z4TFDecorator-aware replacement for inspect.getmodule.)r!   	getmodulero   s    r   rz   rz   p  s    c""r   c                 .    [         R                  " U 5      $ )z1TFDecorator-aware replacement for inspect.getmro.)r!   getmro)clss    r   r|   r|   u  s    ??3r   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z4TFDecorator-aware replacement for inspect.getsource.r   )r!   	getsourcer0   r1   r2   r3   ro   s    r   r   r   z  -    boo77>>sCAFGGr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z8TFDecorator-aware replacement for inspect.getsourcefile.r   )r!   getsourcefiler0   r1   r2   r3   ro   s    r   r   r     s-    !!"//";";"B"B3"G"JKKr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z9TFDecorator-aware replacement for inspect.getsourcelines.r   )r!   getsourcelinesr0   r1   r2   r3   ro   s    r   r   r     s-    ""2??#<#<#C#CC#H#KLLr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z4TFDecorator-aware replacement for inspect.isbuiltin.r   )r!   	isbuiltinr0   r1   r2   r3   ro   s    r   r   r     r   r   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z2TFDecorator-aware replacement for inspect.isclass.r   )r!   isclassr0   r1   r2   r3   ro   s    r   r   r     -    BOO55<<SA!DEEr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z5TFDecorator-aware replacement for inspect.isfunction.r   )r!   
isfunctionr0   r1   r2   r3   ro   s    r   r   r     s-    r88??DQGHHr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ z3TFDecorator-aware replacement for inspect.ismodule.r   )r!   isframer0   r1   r2   r3   ro   s    r   r   r     r   r   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z6TFDecorator-aware replacement for inspect.isgenerator.r   )r!   isgeneratorr0   r1   r2   r3   ro   s    r   r   r     s-     9 9 @ @ Ea HIIr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z>TFDecorator-aware replacement for inspect.isgeneratorfunction.r   )r!   isgeneratorfunctionr0   r1   r2   r3   ro   s    r   r   r     s2    ''
!!((-a0 r   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z3TFDecorator-aware replacement for inspect.ismethod.r   )r!   rZ   r0   r1   r2   r3   ro   s    r   rZ   rZ     -    R__66==cB1EFFr   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ r   )r!   ismoduler0   r1   r2   r3   ro   s    r   r   r     r   r   c                     [         R                  " [        R                  R                  R                  U 5      S   5      $ )z4TFDecorator-aware replacement for inspect.isroutine.r   )r!   	isroutiner0   r1   r2   r3   ro   s    r   r   r     r   r   c                 4    [         R                  " U 5      SS $ )z0TFDecorator-aware replacement for inspect.stack.r   Nr    )contexts    r   r"   r"     s    >>'"12&&r   r'   )r   )(__doc__collectionsr-   inspectr!   tensorflow.compat.v2compatv2r0   rs   r   
namedtupler	   r   r   r   r   r   r$   r/   ri   rk   rn   rt   rw   rz   r|   r   r   r   r   r   r   r   r   r   rZ   r   r   r"   r#   r   r   <module>r      s;   =    ! !
8YG$$	
G 8]##&&K((	
K 8%&&--O4 %%K	I"
6.r]Q@#,$N2 . /
#
 
H
L
M
H
F
I
F
J
G
G
H
'r   