o
    ¡…›iI  ã                   @   s„   d dl Z d dlmZ d dlmZmZ d dlmZ edƒZedƒZ	edƒZ
eƒ Zdeee
ef e	f d	eee
ef e	f fd
d„ZdS )é    N)ÚCallable)ÚConcatenateÚTypeVar)Ú	ParamSpecÚ_PÚ_TÚ_CÚfÚreturnc              	      s<   dˆj  ‰ t ˆ¡dtdtjdtjdtf‡ ‡fdd„ƒ}|S )a  
    Like `@functools.cache` but for methods.

    `@functools.cache` (and similarly `@functools.lru_cache`) shouldn't be used
    on methods because it caches `self`, keeping it alive
    forever. `@cache_method` ignores `self` so won't keep `self` alive (assuming
    no cycles with `self` in the parameters).

    Footgun warning: This decorator completely ignores self's properties so only
    use it when you know that self is frozen or won't change in a meaningful
    way (such as the wrapped function being pure).
    Ú_cache_method_ÚselfÚargsÚkwargsr
   c                    sf   |rt dƒ‚t| ˆ d ƒ }si }t| ˆ |ƒ | |t¡}|tur"|S ˆ| g|¢R i |¤Ž}|||< |S )Nz.cache_method does not accept keyword arguments)ÚAssertionErrorÚgetattrÚsetattrÚgetÚ_cache_sentinel)r   r   r   ÚcacheÚcached_valueÚvalue©Ú
cache_namer	   © úX/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/torch/utils/_functools.pyÚwrap    s   zcache_method.<locals>.wrap)Ú__name__Ú	functoolsÚwrapsr   r   r   r   r   )r	   r   r   r   r   Úcache_method   s   
&r   )r   Úcollections.abcr   Útypingr   r   Útyping_extensionsr   r   r   r   Úobjectr   r   r   r   r   r   Ú<module>   s    ÿþ