o
    ?e6                     @   sV  d Z ddlZddlZddlZddlmZ zejZW n   Y eedr'ej	Z	ne
dg dZ	dd Zeedr@ejZd	d
 ZnejZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd=ddZdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d>d;d<Z%dS )?z6TFDecorator-aware replacements for the inspect module.    N)tf_decoratorFullArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotationsc              	   C   s,   t | tr| S t| j| j| j| jg d i dS )Nr   )
isinstancer   r   r   keywordsr   )argspec r   i/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/keras/utils/tf_inspect.py%_convert_maybe_argspec_to_fullargspec&   s   
r   getfullargspecc              	   C   sP   t | }ttdrt|j|j|j|jd}|S t|j|j|j|jg di d}|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   )targetZfullargspecsZargspecsr   r   r   _getargspec5   s&   
r   c                 C   s   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   r   r   r   _getfullargspecY   s   	r   c                   C   s   t  d d S )z7TFDecorator-aware replacement for inspect.currentframe.   r   r   stackr   r   r   r   currentframee   s   r   c                 C   s   t | tjr
t| S t| \}}tdd |D d}|r|S zt|W S  ty-   Y nw t |t	rSzt|j
W S  tyB   Y nw zt|jW S  tyR   Y n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                 s   s     | ]}|j d ur|j V  qd S N)decorator_argspec).0dr   r   r   	<genexpr>   s
    zgetargspec.<locals>.<genexpr>N)r   	functoolspartial_get_argspec_for_partialr   unwrapnextr   	TypeErrortype__init____new____call__)obj
decoratorsr   specr   r   r   r   j   s6   

r   c                    s  t | j}| jp	i }t| j\ }}} |d  t gt   }|r.||t | d< | D ]\}}| v rD |}	|||	< q2|sJtdq2t	fddt
|D ddu rdt ||dS  fddt
|D }
|
rytd|
 t ||t|d S )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   s     | ]\}}| ur|V  qd S r   r   )r    idxx)
no_defaultr   r   r"      s    z+_get_argspec_for_partial.<locals>.<genexpr>c                    s(   g | ]\}}|u r|kr | qS r   r   )r    ijr   Zfirst_defaultr2   r   r   
<listcomp>   s    z,_get_argspec_for_partial.<locals>.<listcomp>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
ValueErrorr'   	enumerater   tuple)r-   Zn_prune_argspartial_keywordsr   r   r   Zall_defaultskwdefaultr0   Zinvalid_default_valuesr   r5   r   r%      s8   
(


r%   c                 C   s8   t | \}}|D ]}|jdurt|j  S q	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.
  N)r   r&   r   r   r   )r-   r.   r   r!   r   r   r   r      s   
c                     s   | d }| dd }t |}|  t|ddpt|dd}t|r)|r)|f| } fdd|jD } tt|| |jsBdnt	|j}|rbt|j| d |jD ]\}}	| vra|	 |< qU|j
dury|j
 D ]\}
}|
 vrx| |
< ql S )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   NZim_self__self__c                    s   g | ]}| vr|qS r   r   )r    argZ	call_argsr   r   r6   #  s    zgetcallargs.<locals>.<listcomp>)r   copygetattrismethodr   updatedictzipr   r7   r
   r:   )Zfunc_and_positionalnamedr8   
positionalr   thisZremaining_positionalsZdefault_countrC   valuekvr   rD   r   getcallargs  s*   
 
rQ   c                  O   s   t j| i |S r   )r   getframeinfo)r   kwargsr   r   r   rR   1  s   rR   c                 C   
   t | 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r9   r   r   r   rU   5  s   
rU   c                 C   s6   t | d }t|drd|jv r|jd S t|S )z2TFDecorator-aware replacement for inspect.getfile.r   	f_globals__file__)r   r&   r   rW   r   getfile)r9   Zunwrapped_objectr   r   r   rY   D  s   


rY   c                 C   s   t | |S )z5TFDecorator-aware replacement for inspect.getmembers.)r   
getmembers)r9   	predicater   r   r   rZ   R  s   rZ   c                 C   rT   )z4TFDecorator-aware replacement for inspect.getmodule.)r   	getmodulerV   r   r   r   r\   W     
r\   c                 C   rT   )z1TFDecorator-aware replacement for inspect.getmro.)r   getmro)clsr   r   r   r^   \  r]   r^   c                 C      t t| d S )z4TFDecorator-aware replacement for inspect.getsource.r   )r   	getsourcer   r&   rV   r   r   r   ra   a     ra   c                 C   r`   )z8TFDecorator-aware replacement for inspect.getsourcefile.r   )r   getsourcefiler   r&   rV   r   r   r   rc   f  rb   rc   c                 C   r`   )z9TFDecorator-aware replacement for inspect.getsourcelines.r   )r   getsourcelinesr   r&   rV   r   r   r   rd   k  rb   rd   c                 C   r`   )z4TFDecorator-aware replacement for inspect.isbuiltin.r   )r   	isbuiltinr   r&   rV   r   r   r   re   p  rb   re   c                 C   r`   )z2TFDecorator-aware replacement for inspect.isclass.r   )r   isclassr   r&   rV   r   r   r   rf   u  rb   rf   c                 C   r`   )z5TFDecorator-aware replacement for inspect.isfunction.r   )r   
isfunctionr   r&   rV   r   r   r   rg   z  rb   rg   c                 C   r`   z3TFDecorator-aware replacement for inspect.ismodule.r   )r   isframer   r&   rV   r   r   r   ri     rb   ri   c                 C   r`   )z6TFDecorator-aware replacement for inspect.isgenerator.r   )r   isgeneratorr   r&   rV   r   r   r   rj     rb   rj   c                 C   r`   )z>TFDecorator-aware replacement for inspect.isgeneratorfunction.r   )r   isgeneratorfunctionr   r&   rV   r   r   r   rk     rb   rk   c                 C   r`   )z3TFDecorator-aware replacement for inspect.ismethod.r   )r   rG   r   r&   rV   r   r   r   rG     rb   rG   c                 C   r`   rh   )r   ismoduler   r&   rV   r   r   r   rl     rb   rl   c                 C   r`   )z4TFDecorator-aware replacement for inspect.isroutine.r   )r   	isroutiner   r&   rV   r   r   r   rm     rb   rm   r   c                 C   s   t | dd S )z0TFDecorator-aware replacement for inspect.stack.r   Nr   )contextr   r   r   r     s   r   r   )r   )&__doc__collectionsr#   inspectr   Ztensorflow.python.utilr   r   r   r   
namedtupler   r   r   r   r   r   r%   rQ   rR   rU   rY   rZ   r\   r^   ra   rc   rd   re   rf   rg   ri   rj   rk   rG   rl   rm   r   r   r   r   r   <module>   sT   



"4X%
