o
    Vht	                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 er4d dlm
Z
 d dlmZ ed	Zed
edZG dd deje ZdddZdS )    )annotationsN)TYPE_CHECKING)TypeVar)overload)WeakKeyDictionary)Any)CallableTC)boundc                      sR   e Zd Zd fddZe	ddddZeddddZ	dd fddZ  ZS )AtomicCachedPropertyfuncCallable[[C], T]returnNonec                   s"   t  | t | _t | _d S N)super__init__	threadingBoundedSemaphore
_semaphorer   _locks)selfr   	__class__ j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/utils/threading.pyr      s   
zAtomicCachedProperty.__init__.instanceownertype[Any] | NoneAtomicCachedProperty[T]c                 C     d S r   r   r   r   r   r   r   r   __get__   s   zAtomicCachedProperty.__get__objectr	   c                 C  r!   r   r   r"   r   r   r   r#      s   NC | NoneAtomicCachedProperty[T] | Tc                   s   |d u r| S || j vr*| j || j vrt | j |< W d    n1 s%w   Y  | j |  t ||W  d    S 1 sAw   Y  d S r   )r   r   r   Lockr   r#   r"   r   r   r   r#   "   s   

$)r   r   r   r   ).)r   r   r   r   r   r    )r   r$   r   r   r   r	   r   )r   r%   r   r   r   r&   )__name__
__module____qualname__r   r   r#   __classcell__r   r   r   r   r      s    r   r   r   r   r    c                 C  s   t | S )a  
    A thread-safe implementation of functools.cached_property that ensures lazily-computed
    properties are calculated only once, even in multithreaded environments.

    This property decorator works similar to functools.cached_property but employs
    thread locks and a bounded semaphore to handle concurrent access safely.

    The computed value is cached on the instance itself and is reused for subsequent
    accesses unless explicitly invalidated. The added thread-safety makes it ideal for
    situations where multiple threads might access and compute the property simultaneously.

    Note:
    - The cache is stored in the instance dictionary just like `functools.cached_property`.

    :param func: The function to be turned into a thread-safe cached property.
    )r   )r   r   r   r   atomic_cached_property4   s   r,   )r   r   r   r    )
__future__r   	functoolsr   typingr   r   r   weakrefr   r   r   r	   r$   r
   cached_propertyr   r,   r   r   r   r   <module>   s    