o
    h;                     @  sV  U d dl mZ d dlZ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Zd dlmZ d dlmZ d dlmZ d d	lmZ d dlZerP	 ejd
k r[d dlmZ ee  Zd0ddZG dd de
Ze Zded< d1ddZd2ddZ d3d"d#Z!d1d$d%Z"ej#d&d'd4d*d+Z$ej#d&d'd4d,d-Z%ej#d&d'd4d.d/Z&dS )5    )annotationsN)Callable)
NamedTuple)TYPE_CHECKING)Config)Item)StashKey)tracemalloc_message)      )ExceptionGroup
iterationsintreturnNonec                 C  s   t | D ]}t  qd S N)rangegccollect)r   _ r   \/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/unraisableexception.pygc_collect_harder   s   
r   c                   @  s&   e Zd ZU ded< ded< ded< dS )UnraisableMetastrmsg	cause_msgzBaseException | None	exc_valueN)__name__
__module____qualname____annotations__r   r   r   r   r   $   s   
 r   z;StashKey[collections.deque[UnraisableMeta | BaseException]]unraisable_exceptionsconfigr   c              
   C  s   | j t j}g }d }d }zn	 z| }W n	 ty   Y nHw t|tr/td}||_|| q|j	}z
t
t| W n& tjyb } z|jd urS|jf|_|j|_|| W Y d }~nd }~ww qt|dkrn|d |rutd|W ~~~d S ~~~w )NTz&Failed to process unraisable exception   r   z&multiple unraisable exception warnings)stashr"   pop
IndexError
isinstanceBaseExceptionRuntimeError	__cause__appendr   warningswarnpytest PytestUnraisableExceptionWarningr   r   argslenr   )r#   pop_unraisableerrorsmeta
hook_errorr   er   r   r   collect_unraisable/   sB   





r8   	prev_hook*Callable[[sys.UnraisableHookArgs], object]c                 C  sL   | j td}zzt| t|  W |t_n|t_w W | j t= d S | j t= w )N   )r%   getgc_collect_iterations_keyr   r8   sysunraisablehookr"   )r#   r9   gc_collect_iterationsr   r   r   cleanupV   s   
rA   
unraisablesys.UnraisableHookArgsr,   2Callable[[UnraisableMeta | BaseException], object]c         	   
   C  s   z?| j d u rdn| j }| d| j}ddt| j| j| j }dt| j }|| | }|| }|t	||| jd W d S  t
yP } z||  d }~ww )NzException ignored inz: z

 
)r   r   r   )err_msgobjectjoin	tracebackformat_exceptionexc_typer   exc_tracebackr	   r   r)   )	rB   r,   rG   summarytraceback_messagetracemalloc_tbr   r   r7   r   r   r   unraisable_hookf   s4   
rQ   c                 C  sD   t j}t }|| jt< | tjt	| |d tjt
|jdt _d S )N)r#   r9   )r,   )r>   r?   collectionsdequer%   r"   add_cleanup	functoolspartialrA   rQ   r,   )r#   r9   rS   r   r   r   pytest_configure   s
   
rW   T)trylastitemr   c                 C     t | j d S r   r8   r#   rY   r   r   r   pytest_runtest_setup      r]   c                 C  rZ   r   r[   r\   r   r   r   pytest_runtest_call   r^   r_   c                 C  rZ   r   r[   r\   r   r   r   pytest_runtest_teardown   r^   r`   )r   r   r   r   )r#   r   r   r   )r#   r   r9   r:   r   r   )rB   rC   r,   rD   r   r   )rY   r   r   r   )'
__future__r   rR   collections.abcr   rU   r   r>   rJ   typingr   r   r-   _pytest.configr   _pytest.nodesr   _pytest.stashr   _pytest.tracemallocr	   r/   version_infoexceptiongroupr   r   r=   r   r   r"   r!   r8   rA   rQ   rW   hookimplr]   r_   r`   r   r   r   r   <module>   sD    





'

)


