o
    f#                     @   s>   d dl mZ d dlmZ dgZG dd dZG dd dZdS )    ref)GenericAliasWeakSetc                   @   s$   e Zd Zdd Zdd Zdd ZdS )_IterationGuardc                 C   s   t || _d S N)r   weakcontainer)selfr    r
   "/usr/lib/python3.10/_weakrefset.py__init__   s   z_IterationGuard.__init__c                 C   s    |   }|d ur|j|  | S r   )r   
_iteratingadd)r	   wr
   r
   r   	__enter__   s   z_IterationGuard.__enter__c                 C   s8   |   }|d ur|j}||  |s|  d S d S d S r   )r   r   remove_commit_removals)r	   etbr   sr
   r
   r   __exit__   s   
z_IterationGuard.__exit__N)__name__
__module____qualname__r   r   r   r
   r
   r
   r   r      s    r   c                   @   s&  e Zd Zd@ddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZeZd d! Zd"d# Zd$d% ZeZd&d' Zd(d) Zd*d+ ZeZd,d- Zd.d/ ZeZd0d1 Zd2d3 Zd4d5 Z e Z!d6d7 Z"d8d9 Z#d:d; Z$e$Z%d<d= Z&d>d? Z'e(e)Z*dS )Ar   Nc                 C   sF   t  | _t| fdd}|| _g | _t  | _|d ur!| | d S d S )Nc                 S   s8   | }|d ur|j r|j|  d S |j|  d S d S r   )r   _pending_removalsappenddatadiscard)itemselfrefr	   r
   r
   r   _remove'   s   z!WeakSet.__init__.<locals>._remove)setr   r   r!   r   r   update)r	   r   r!   r
   r
   r   r   %   s   zWeakSet.__init__c                 C   s<   | j j}| jj}	 z| }W n
 ty   Y d S w || q	r   )r   popr   r   
IndexError)r	   r$   r   r   r
   r
   r   r   5   s   
zWeakSet._commit_removalsc                 c   sP    t |  | jD ]}| }|d ur|V  q	W d    d S 1 s!w   Y  d S r   )r   r   r	   itemrefr   r
   r
   r   __iter__?   s   

"zWeakSet.__iter__c                 C   s   t | jt | j S r   )lenr   r   r	   r
   r
   r   __len__H      zWeakSet.__len__c                 C   s,   zt |}W n
 ty   Y dS w || jv S )NF)r   	TypeErrorr   )r	   r   wrr
   r
   r   __contains__K   s   
zWeakSet.__contains__c                 C   s   | j t| ft| dd fS )N__dict__)	__class__listgetattrr*   r
   r
   r   
__reduce__R   s   
zWeakSet.__reduce__c                 C   s&   | j r|   | jt|| j d S r   )r   r   r   r   r   r!   r	   r   r
   r
   r   r   V   s   zWeakSet.addc                 C   s   | j r|   | j  d S r   )r   r   r   clearr*   r
   r
   r   r6   [   s   zWeakSet.clearc                 C   s
   |  | S r   r1   r*   r
   r
   r   copy`      
zWeakSet.copyc                 C   sL   | j r|   	 z| j }W n ty   tdd w | }|d ur%|S q)NTzpop from empty WeakSet)r   r   r   r$   KeyErrorr&   r
   r
   r   r$   c   s   
zWeakSet.popc                 C   "   | j r|   | jt| d S r   )r   r   r   r   r   r5   r
   r
   r   r   o      zWeakSet.removec                 C   r;   r   )r   r   r   r   r   r5   r
   r
   r   r   t   r<   zWeakSet.discardc                 C   s&   | j r|   |D ]}| | q	d S r   )r   r   r   )r	   otherelementr
   r
   r   r#   y   s
   zWeakSet.updatec                 C   s   |  | | S r   )r#   r	   r=   r
   r
   r   __ior__   s   
zWeakSet.__ior__c                 C      |   }|| |S r   )r8   difference_updater	   r=   newsetr
   r
   r   
difference      
zWeakSet.differencec                 C      |  | d S r   )__isub__r?   r
   r
   r   rB         zWeakSet.difference_updatec                 C   s>   | j r|   | |u r| j  | S | jdd |D  | S )Nc                 s       | ]}t |V  qd S r   r   .0r   r
   r
   r   	<genexpr>       z#WeakSet.__isub__.<locals>.<genexpr>)r   r   r   r6   rB   r?   r
   r
   r   rH      s   
zWeakSet.__isub__c                    s      fdd|D S )Nc                 3   s    | ]	}| v r|V  qd S r   r
   rK   r*   r
   r   rM          z'WeakSet.intersection.<locals>.<genexpr>r7   r?   r
   r*   r   intersection      zWeakSet.intersectionc                 C   rG   r   )__iand__r?   r
   r
   r   intersection_update   rI   zWeakSet.intersection_updatec                 C   s(   | j r|   | jdd |D  | S )Nc                 s   rJ   r   r   rK   r
   r
   r   rM      rN   z#WeakSet.__iand__.<locals>.<genexpr>)r   r   r   rS   r?   r
   r
   r   rR      s   zWeakSet.__iand__c                 C      | j dd |D S )Nc                 s   rJ   r   r   rK   r
   r
   r   rM      rN   z#WeakSet.issubset.<locals>.<genexpr>)r   issubsetr?   r
   r
   r   rU         zWeakSet.issubsetc                 C   s   | j ttt|k S r   r   r"   mapr   r?   r
   r
   r   __lt__   r,   zWeakSet.__lt__c                 C   rT   )Nc                 s   rJ   r   r   rK   r
   r
   r   rM      rN   z%WeakSet.issuperset.<locals>.<genexpr>)r   
issupersetr?   r
   r
   r   rZ      rV   zWeakSet.issupersetc                 C   s   | j ttt|kS r   rW   r?   r
   r
   r   __gt__   r,   zWeakSet.__gt__c                 C   s$   t || jstS | jttt|kS r   )
isinstancer1   NotImplementedr   r"   rX   r   r?   r
   r
   r   __eq__   s   zWeakSet.__eq__c                 C   rA   r   )r8   symmetric_difference_updaterC   r
   r
   r   symmetric_difference   rF   zWeakSet.symmetric_differencec                 C   rG   r   )__ixor__r?   r
   r
   r   r_      rI   z#WeakSet.symmetric_difference_updatec                    sB    j r    |u r j   S  j fdd|D   S )Nc                 3   s    | ]	}t | jV  qd S r   )r   r!   rK   r*   r
   r   rM      rO   z#WeakSet.__ixor__.<locals>.<genexpr>)r   r   r   r6   r_   r?   r
   r*   r   ra      s   
zWeakSet.__ixor__c                 C   s   |  dd | |fD S )Nc                 s   s    | ]
}|D ]}|V  qqd S r   r
   )rL   r   r   r
   r
   r   rM      s    z WeakSet.union.<locals>.<genexpr>r7   r?   r
   r
   r   union   rQ   zWeakSet.unionc                 C   s   t | |dkS )Nr   )r)   rP   r?   r
   r
   r   
isdisjoint   s   zWeakSet.isdisjointc                 C   s
   t | jS r   )reprr   r*   r
   r
   r   __repr__   r9   zWeakSet.__repr__r   )+r   r   r   r   r   r(   r+   r/   r4   r   r6   r8   r$   r   r   r#   r@   rE   __sub__rB   rH   rP   __and__rS   rR   rU   __le__rY   rZ   __ge__r[   r^   r`   __xor__r_   ra   rb   __or__rc   re   classmethodr   __class_getitem__r
   r
   r
   r   r   $   sN    

			N)_weakrefr   typesr   __all__r   r   r
   r
   r
   r   <module>   s
   