o
    /wÖiú  ã                   @  sb   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dlm
Z
 G dd„ dƒZdS )é    )ÚannotationsN)ÚTracebackType)ÚAny)ÚIOc                      s^   e Zd ZU g Zded< d‡ fdd„Zdd
d„Zddd„Zddd„Zddd„Z	ddd„Z
‡  ZS ) ÚNamedTemporaryFilePoolzlist[IO[Any]]Útempfile_poolÚkwargsr   Úreturnú'NamedTemporaryFilePool'c                   s0   t | dƒstt| ƒ | ¡| _t | jj¡ | jS )NÚ	_instance)ÚhasattrÚsuperr   Ú__new__r   ÚatexitÚregisterÚcleanup)Úclsr   ©Ú	__class__© úY/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/optuna/testing/tempfile_pool.pyr      s   
zNamedTemporaryFilePool.__new__ÚNonec                 K  s
   || _ d S ©N)r   )Úselfr   r   r   r   Ú__init__   s   
zNamedTemporaryFilePool.__init__úIO[Any]c                 C  s,   t jdddi| j¤Ž| _| j | j¡ | jS )NÚdeleteFr   )ÚtempfileÚNamedTemporaryFiler   Ú	_tempfiler   Úappend©r   r   r   r   r      s   zNamedTemporaryFilePool.tempfilec                 C  s$   t  ¡  | jD ]}t |j¡ qd S r   )ÚgcÚcollectr   ÚosÚunlinkÚname)r   Úir   r   r   r       s   
ÿzNamedTemporaryFilePool.cleanupc                 C  s   |   ¡ S r   )r   r!   r   r   r   Ú	__enter__%   s   z NamedTemporaryFilePool.__enter__Úexc_typeútype[BaseException]Úexc_valÚBaseExceptionÚexc_tbr   c                 C  s   | j  ¡  d S r   )r   Úclose)r   r)   r+   r-   r   r   r   Ú__exit__(   s   zNamedTemporaryFilePool.__exit__)r   r   r	   r
   )r   r   r	   r   )r	   r   )r	   r   )r)   r*   r+   r,   r-   r   r	   r   )Ú__name__Ú
__module__Ú__qualname__r   Ú__annotations__r   r   r   r   r(   r/   Ú__classcell__r   r   r   r   r      s   
 



r   )Ú
__future__r   r   r"   r$   r   Útypesr   Útypingr   r   r   r   r   r   r   Ú<module>   s   