
    BVh6                        d Z ddlZddlZddlZddlmZ 	 ej                  Z eed      rej                  Z	n ej                  dg d      Z	d Z eed      rej                  Zd Znej                  Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd"dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d  Z$d#d!Z%y#  Y xY w)$z6TFDecorator-aware replacements for the inspect module.    N)tf_decoratorFullArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotationsc           	          t        | t              r| S t        | j                  | j                  | j                  | j
                  g d i       S )Nr   )
isinstancer   r   r   keywordsr	   )argspecs    X/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/keras/utils/tf_inspect.py%_convert_maybe_argspec_to_fullargspecr   &   sG    %N	<<oo
     getfullargspecc           	      "   t        |       }t        t        d      r9t        |j                  |j
                  |j                  |j                        }|S t        |j                  |j
                  |j                  |j                  g di       }|S )a  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.
    ArgSpec)r   r   r   r	   Nr   )	r   hasattr_inspectr   r   r   r   r	   r   )targetfullargspecsargspecss      r   _getargspecr   5   s      "&)Lx#  &&%%((	*h O   &&""((h Or   c                 *    t        t        |             S )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   Y   s     1F1CDDr   c                  6    t        j                         d   d   S )z7TFDecorator-aware replacement for inspect.currentframe.   r   r   stack r   r   currentframer%   e   s    		!	Q	r   c                    t        | t        j                        rt        |       S t	        j
                  |       \  }}t        d |D        d      }|r|S 	 t        |      S # t        $ r Y nw xY wt        |t              rJ	 t        |j                        S # t        $ r Y nw xY w	 t        |j                        S # t        $ r Y nw xY wt        t        |      j                        S )aJ  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   L   K   | ]  }|j                   |j                     y wN)decorator_argspec).0ds     r   	<genexpr>zgetargspec.<locals>.<genexpr>   s*      3%%1 "" 3s   "$N)r   	functoolspartial_get_argspec_for_partialr   unwrapnextr   	TypeErrortype__init____new____call__)obj
decoratorsr   specs       r   r   r   j   s    & Y&&'#C((#**3/*f	 3"348
:$ 
K	v	 		 )) 
(( 

 
T&\**	++s6   
A! !	A-,A-B 	B"!B"&B; ;	CCc           
      n   t        | j                        }| j                  xs i }t        | j                        \  }}}}||d }t               gt        |      z  }|r||t        |       d |j                         D ]-  \  }}	||v r|j                  |      }
|	||
<   !|r$t        d       t        fdt        |      D        d      }|t        |||d      S t        |      D cg c]  \  }}|u r
||kD  r||    }}}|rt        d|z        t        |||t        ||d             S c c}}w )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   2   K   | ]  \  }}|us|  y wr(   r$   )r*   idxx
no_defaults      r   r,   z+_get_argspec_for_partial.<locals>.<genexpr>   s     HvsAAZ4GsHs   zSome arguments %s 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
ValueErrorr1   	enumerater   tuple)r7   n_prune_argspartial_keywordsr   r   r   r	   all_defaultskwdefaultr<   first_defaultijinvalid_default_valuesr>   s                  @r   r/   r/      s|   P SXX,\\'R&0&:#$8 
lm	$
 x*D	),$,L#h-! &++- ?kb'	TzJJrNc!l3 > ? ?? H<0H$P- 4(D11 $L1!Q	
jQ. 1g 
 
 68NO P P 
w%]^0L*M	NNs   ,D1c                     t        j                  |       \  }}|D ]%  }|j                  t        |j                        c S  t	        |      S )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.
  )r   r0   r)   r   r   )r7   r8   r   r+   s       r   r   r      sT     $**3/*f Ha&213F3FGGH 
	  r   c                  b   | d   }| dd }t        |      }|j                         }t        |dd      xs t        |dd      }t        |      r|r|f|z   }|j                  D cg c]	  }||vs| }}|j                  t        t        ||                   |j                  sdnt        |j                        }	|	r6t        |j                  |	 d |j                        D ]  \  }}
||vs|
||<    |j                  ,|j                  j                         D ]  \  }}||vs|||<    |S c c}w )aX  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	   r?   r   rB   )func_and_positionalnamedr@   
positionalr   	call_argsthisargremaining_positionalsdefault_countvaluekvs                r   getcallargsre     sD     
Q	$"12&*4 'jjl)	y$	'	J74T+J$d^:%J*1,,O3#Y:N3OO41:>?@"++!W5E5E1F-',,~79I9IJ 
U	I		# '&&,,. 1	
)		! 
 Ps   #	D,-D,c                  ,    t        j                  | i |S r(   )r   getframeinfo)r   kwargss     r   rg   rg   1  s    				/	//r   c                 ,    t        j                  |       S )a(  TFDecorator-aware replacement for inspect.getdoc.

  Args:
    object: 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rA   s    r   rj   rj   5  s     
	  r   c                     t        j                  |       d   }t        |d      rd|j                  v r|j                  d   S t	        j
                  |      S )z2TFDecorator-aware replacement for inspect.getfile.r!   	f_globals__file__)r   r0   r   rm   r   getfile)rA   unwrapped_objects     r   ro   ro   D  sW    !((03 ,$...%%j11			*	++r   c                 .    t        j                  | |      S )z5TFDecorator-aware replacement for inspect.getmembers.)r   
getmembers)rA   	predicates     r   rr   rr   R  s    			VY	//r   c                 ,    t        j                  |       S )z4TFDecorator-aware replacement for inspect.getmodule.)r   	getmodulerk   s    r   ru   ru   W  s    			F	##r   c                 ,    t        j                  |       S )z1TFDecorator-aware replacement for inspect.getmro.)r   getmro)clss    r   rw   rw   \  s    		r   c                 X    t        j                  t        j                  |       d         S )z4TFDecorator-aware replacement for inspect.getsource.r!   )r   	getsourcer   r0   rk   s    r   rz   rz   a  #    			L//7:	;;r   c                 X    t        j                  t        j                  |       d         S )z8TFDecorator-aware replacement for inspect.getsourcefile.r!   )r   getsourcefiler   r0   rk   s    r   r}   r}   f  s#    			 3 3F ;A >	??r   c                 X    t        j                  t        j                  |       d         S )z9TFDecorator-aware replacement for inspect.getsourcelines.r!   )r   getsourcelinesr   r0   rk   s    r   r   r   k  s#    		 	 !4!4V!<Q!?	@@r   c                 X    t        j                  t        j                  |       d         S )z4TFDecorator-aware replacement for inspect.isbuiltin.r!   )r   	isbuiltinr   r0   rk   s    r   r   r   p  r{   r   c                 X    t        j                  t        j                  |       d         S )z2TFDecorator-aware replacement for inspect.isclass.r!   )r   isclassr   r0   rk   s    r   r   r   u  #    			,--f5a8	99r   c                 X    t        j                  t        j                  |       d         S )z5TFDecorator-aware replacement for inspect.isfunction.r!   )r   
isfunctionr   r0   rk   s    r   r   r   z  s#    			\008;	<<r   c                 X    t        j                  t        j                  |       d         S z3TFDecorator-aware replacement for inspect.ismodule.r!   )r   isframer   r0   rk   s    r   r   r     r   r   c                 X    t        j                  t        j                  |       d         S )z6TFDecorator-aware replacement for inspect.isgenerator.r!   )r   isgeneratorr   r0   rk   s    r   r   r     s#    			l11&9!<	==r   c                 X    t        j                  t        j                  |       d         S )z>TFDecorator-aware replacement for inspect.isgeneratorfunction.r!   )r   isgeneratorfunctionr   r0   rk   s    r   r   r     s#    		%	%l&9&9&&A!&D	EEr   c                 X    t        j                  t        j                  |       d         S )z3TFDecorator-aware replacement for inspect.ismethod.r!   )r   rV   r   r0   rk   s    r   rV   rV     #    			<..v6q9	::r   c                 X    t        j                  t        j                  |       d         S r   )r   ismoduler   r0   rk   s    r   r   r     r   r   c                 X    t        j                  t        j                  |       d         S )z4TFDecorator-aware replacement for inspect.isroutine.r!   )r   	isroutiner   r0   rk   s    r   r   r     r{   r   c                 2    t        j                  |       dd S )z0TFDecorator-aware replacement for inspect.stack.r!   Nr"   )contexts    r   r#   r#     s    		 	$$r   r(   )r!   )&__doc__collectionsr-   inspectr   tensorflow.python.utilr   r   r   r   
namedtupler   r   r   r   r   r%   r/   re   rg   rj   ro   rr   ru   rw   rz   r}   r   r   r   r   r   r   r   rV   r   r   r#   r$   r   r   <module>r      s   =    /'
 8]#$$+&&&} 7 +
 8%&++/ D ##+	E 
1,hUOp!,"J0!,0
$

<
@
A
<
:
=
:
>
F
;
;
<
%Is   C C