o
    yAf+                     @  s   d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZmZmZmZ er4d dl
mZ ededd	Zed
edZededd	ZededZd ddZd!ddZG dd deee ZG dd dee eZdS )"    )annotations)CallableSequence)partial)getmroisclass)TYPE_CHECKINGGenericTypeTypeVarcastoverload)Self_BaseExceptionT_coT)bound	covariant_BaseExceptionT)r   _ExceptionT_co_ExceptionTexcBaseExceptionparentstuple[type[BaseException]]returnboolc                 C  s*   t | jd d D ]	}||v r dS q	dS )NTF)r   	__class__)r   r   cls r   ?/usr/lib/python3.10/site-packages/exceptiongroup/_exceptions.pycheck_direct_subclass   s
   r    	condition`type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co], bool]$Callable[[_BaseExceptionT_co], bool]c                 C  st   t | rtttt | trtt| fdS t| tr-t	dd | D r)tt| dS tdt
| r6td| S td)N)r   c                 s  s"    | ]}t |ot|tV  qd S N)r   
issubclassr   ).0xr   r   r   	<genexpr>%   s     z'get_condition_filter.<locals>.<genexpr>zCallable[[BaseException], bool]z?expected a function, exception type or tuple of exception types)r   r%   r   r
   r   r   r    
isinstancetupleallcallable	TypeError)r!   r   r   r   get_condition_filter   s   


r.   c                      s   e Zd ZdZd7 fdd	Zd8ddZed9ddZed:ddZe	d;ddZ
e	d<ddZ
e	d=ddZ
d>ddZ
e	d?d!d"Ze	d@d$d"Ze	dAd&d"ZdBd)d"Ze	dCd-d.Ze	dDd1d.ZdDd2d.Zd9d3d4Zd9d5d6Z  ZS )EBaseExceptionGroupz/A combination of multiple unrelated exceptions._BaseExceptionGroup__messagestr_BaseExceptionGroup__exceptionsSequence[_BaseExceptionT_co]r   r   c                   s   t |tstdt| t |tstd|stdt|D ]\}}t |ts2td| dq!| tu rBt	dd |D rBt
} t| tra|D ]}t |ts`| t
u rXtdtd	| jqIt | ||}||_||_|S )
Nzargument 1 must be str, not z/second argument (exceptions) must be a sequencez9second argument (exceptions) must be a non-empty sequencezItem z4 of second argument (exceptions) is not an exceptionc                 s  s    | ]}t |tV  qd S r$   )r)   	Exception)r&   r   r   r   r   r(   C   s    z-BaseExceptionGroup.__new__.<locals>.<genexpr>z/Cannot nest BaseExceptions in an ExceptionGroupzCannot nest BaseExceptions in )r)   r1   r-   typer   
ValueError	enumerater   r/   r+   ExceptionGroupr%   r4   __name__super__new___message_exceptions)r   r0   r2   ir   instancer   r   r   r;   0   s@   







zBaseExceptionGroup.__new__noteNonec                 C  sF   t |tstd|dt|j dt| dsg | _| j| d S )NzExpected a string, got note=z (type )	__notes__)r)   r1   r-   r5   r9   hasattrrD   append)selfrA   r   r   r   add_noteW   s   

zBaseExceptionGroup.add_notec                 C  s   | j S r$   )r<   rG   r   r   r   messageb   s   zBaseExceptionGroup.messageGtuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]c                 C  s
   t | jS r$   )r*   r=   rI   r   r   r   
exceptionsf   s   
zBaseExceptionGroup.exceptions_BaseExceptionGroup__condition1type[_ExceptionT] | tuple[type[_ExceptionT], ...]"ExceptionGroup[_ExceptionT] | Nonec                 C     d S r$   r   rG   rM   r   r   r   subgroupl      zBaseExceptionGroup.subgroup9type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]*BaseExceptionGroup[_BaseExceptionT] | Nonec                 C  rP   r$   r   rQ   r   r   r   rR   r   rS   +Callable[[_BaseExceptionT_co | Self], bool]-BaseExceptionGroup[_BaseExceptionT_co] | Nonec                 C  rP   r$   r   rQ   r   r   r   rR   x   rS   gtype[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co | Self], bool]c                 C  s   t |}d}|| r| S g }| jD ](}t|tr-||}|d ur&|| ||ur,d}q||r7|| qd}q|s>| S |rS| |}| j|_| j|_| j	|_	|S d S )NFT)
r.   rL   r)   r/   rR   rF   derive	__cause____context____traceback__)rG   rM   r!   modifiedrL   r   rR   groupr   r   r   rR   ~   s2   




Xtuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  rP   r$   r   rQ   r   r   r   split      zBaseExceptionGroup.split`tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  rP   r$   r   rQ   r   r   r   r`      ra   ctuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  rP   r$   r   rQ   r   r   r   r`      ra   r"   !  tuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None] | tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None] | tuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c           
      C  s   t |}|| r| d fS g }g }| jD ]0}t|tr4||\}}|d ur*|| |d ur3|| q||r>|| q|| qd }|rY| |}| j|_| j|_| j	|_	d }	|rn| |}	| j|	_| j|	_| j	|	_	||	fS r$   )
r.   rL   r)   r/   r`   rF   rY   rZ   r[   r\   )
rG   rM   r!   Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr   r   r   r`      s:   





_BaseExceptionGroup__excsSequence[_ExceptionT]ExceptionGroup[_ExceptionT]c                 C  rP   r$   r   rG   re   r   r   r   rY      s   zBaseExceptionGroup.deriveSequence[_BaseExceptionT]#BaseExceptionGroup[_BaseExceptionT]c                 C  rP   r$   r   rh   r   r   r   rY      rS   c                 C  s&   t | j|}t| drt| j|_|S )NrD   )r/   rJ   rE   listrD   )rG   re   egr   r   r   rY      s   
c                 C  s4   t | jdkr	dnd}| j dt | j d| dS )N    sz (z sub-exceptionrC   )lenr=   rJ   )rG   suffixr   r   r   __str__  s   zBaseExceptionGroup.__str__c                 C  s   | j j d| jd| jdS )N(z, rC   )r   r9   rJ   r=   rI   r   r   r   __repr__  s   zBaseExceptionGroup.__repr__)r0   r1   r2   r3   r   r   )rA   r1   r   rB   )r   r1   )r   rK   )rM   rN   r   rO   )rM   rT   r   rU   )rM   rV   r   rW   )rM   rX   r   rU   )rM   rN   r   r_   )rM   rT   r   rb   )rM   rV   r   rc   )rM   r"   r   rd   )re   rf   r   rg   )re   ri   r   rj   )r9   
__module____qualname____doc__r;   rH   propertyrJ   rL   r   rR   r`   rY   rr   rt   __classcell__r   r   r@   r   r/   -   s:    
'
$
6


r/   c                      s   e Zd Zd fddZerBedd
dZedddZed ddZd! fddZed"ddZ	ed#ddZ	d$ fddZ	  Z
S   Z
S )%r8   _ExceptionGroup__messager1   _ExceptionGroup__exceptionsSequence[_ExceptionT_co]r   r   c                   s   t  | ||S r$   )r:   r;   )r   rz   r{   r@   r   r   r;     s   zExceptionGroup.__new__;tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]c                 C  rP   r$   r   rI   r   r   r   rL     rS   zExceptionGroup.exceptions_ExceptionGroup__conditionrN   rO   c                 C  rP   r$   r   rG   r~   r   r   r   rR     rS   zExceptionGroup.subgroup'Callable[[_ExceptionT_co | Self], bool]%ExceptionGroup[_ExceptionT_co] | Nonec                 C  rP   r$   r   r   r   r   r   rR   !  rS   Ttype[_ExceptionT] | tuple[type[_ExceptionT], ...] | Callable[[_ExceptionT_co], bool]c                      t  |S r$   )r:   rR   r   r@   r   r   rR   '  s   Ptuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  rP   r$   r   r   r   r   r   r`   /     zExceptionGroup.splitStuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  rP   r$   r   r   r   r   r   r`   7  r   rG   c                   r   r$   )r:   r`   r   r@   r   r   r`   ?  s   )rz   r1   r{   r|   r   r   )r   r}   )r~   rN   r   rO   )r~   r   r   r   )r~   r   r   rO   )r~   rN   r   r   )r~   r   r   r   )rG   r   r~   r   r   r   )r9   ru   rv   r;   r   rx   rL   r   rR   r`   ry   r   r   r@   r   r8     s     r8   N)r   r   r   r   r   r   )r!   r"   r   r#   )
__future__r   collections.abcr   r   	functoolsr   inspectr   r   typingr   r	   r
   r   r   r   r   r   r   r   r4   r   r   r    r.   r/   r8   r   r   r   r   <module>   s      


 c