
    BVh,                     Z    d Z ddlZddlZ G d de      Z G d de      Z G d de      Zy)	zCaching utilities.    Nc                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)	_TransformedFnCachea5  Generic hierarchical cache for transformed functions.

  The keys are soft references (i.e. they are discarded when the key is
  destroyed) created from the source function by `_get_key`. The subkeys are
  strong references and can be any value. Typically they identify different
  kinds of transformation.
  )_cachec                 6    t        j                         | _        y N)weakrefWeakKeyDictionaryr   selfs    V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/autograph/pyct/cache.py__init__z_TransformedFnCache.__init__!   s    ++-DK    c                     t        d      )Nzsubclasses must override)NotImplementedErrorr   entitys     r   _get_keyz_TransformedFnCache._get_key$   s    
8
99r   c                 j    | j                  |      }| j                  j                  |d       }|y||v S )NFr   r   get)r   r   subkeykeyparents        r   hasz_TransformedFnCache.has'   s7    
--
C[[__S$'F~Vr   c                     | j                  |      }| j                  j                  |d       }|i x| j                  |<   }|S r   r   )r   r   r   r   s       r   __getitem__z_TransformedFnCache.__getitem__.   sC    
--
C[[__S$'F~ #%$dkk#Mr   c                 ,    t        | j                        S r   )lenr   r
   s    r   __len__z_TransformedFnCache.__len__7   s    t{{r   N)
__name__
__module____qualname____doc__	__slots__r   r   r   r   r    r   r   r   r      s'     ).:r   r   c                       e Zd ZdZd Zy)CodeObjectCachea@  A function cache based on code objects.

  Code objects are good proxies for the source code of a function.

  This cache efficiently handles functions that share code objects, such as
  functions defined in a loop, bound methods, etc.

  The cache falls back to the function object, if it doesn't have a code object.
  c                 6    t        |d      r|j                  S |S )N__code__)hasattrr)   r   s     r   r   zCodeObjectCache._get_keyF   s    vz"__mr   Nr    r!   r"   r#   r   r%   r   r   r'   r'   ;   s    r   r'   c                       e Zd ZdZd Zy)UnboundInstanceCacheaH  A function cache based on unbound function objects.

  Using the function for the cache key allows efficient handling of object
  methods.

  Unlike the _CodeObjectCache, this discriminates between different functions
  even if they have the same code. This is needed for decorators that may
  masquerade as another function.
  c                 H    t        j                  |      r|j                  S |S r   )inspectismethod__func__r   s     r   r   zUnboundInstanceCache._get_keyX   s    __Mr   Nr+   r%   r   r   r-   r-   M   s    r   r-   )r#   r/   r   objectr   r'   r-   r%   r   r   <module>r3      s7      "& "J) $. r   