U
    Rh,                     @  s   d dl mZ d dl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jdk rvd dlmZ ed	ed
edZededZeded
edZededZedddZedddZddddddZdddddZdd  ZG d!d deee ZG d"d dee eZ dS )#    )annotationsN)CallableSequence)partial)getmroisclass)TYPE_CHECKINGGenericTypeTypeVarcastoverload)      )r   _BaseExceptionT_coT)boundZ	covariantdefault_BaseExceptionT)r   _ExceptionT_co_ExceptionT_ExceptionGroupSelfExceptionGroup_BaseExceptionGroupSelfBaseExceptionGroupBaseExceptionztuple[type[BaseException]]bool)excparentsreturnc                 C  s*   t | jd d D ]}||kr dS qdS )NTF)r   	__class__)r   r   cls r"   @./venv/lib/python3.8/site-packages/exceptiongroup/_exceptions.pycheck_direct_subclass   s    r$   `type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co], bool]z$Callable[[_BaseExceptionT_co], bool])	conditionr   c                 C  sr   t | r*tttt | tr*tt| fdS t| trTt	dd | D rftt| dS nt
| rftd| S tdd S )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    
 

r1   c                 C  s<   |  |}| j|_| j|_| j|_t| dr8t| j|_|S )N	__notes__)derive	__cause____context____traceback__hasattrlistr2   )selfZexcsZegr"   r"   r#   _derive_and_copy_attributes5   s    

r:   c                      s`  e Zd ZdZddddd fddZddd	d
dddZdd
dddZeddddZeddddZ	e
dddddZe
dddddZe
dd dd!dZd"ddd#dZe
dd$dd%d&Ze
dd'dd(d&Ze
dd)dd*d&Zd+d,dd-d&Ze
d.d/d0d1d2Ze
d3d4d0d5d2Zd3d4d0d6d2Zddd7d8Zddd9d:Z  ZS );r   z/A combination of multiple unrelated exceptions.ztype[_BaseExceptionGroupSelf]strzSequence[_BaseExceptionT_co]r   )r!   _BaseExceptionGroup__message_BaseExceptionGroup__exceptionsr   c                   s   t |tstdt| t |ts.td|s:tdt|D ]"\}}t |tsBtd| dqB| tkrt	dd |D rt
} t| tr|D ]0}t |ts| t
krtdqtd	| jqt | ||}t||_|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+   X   s     z-BaseExceptionGroup.__new__.<locals>.<genexpr>z/Cannot nest BaseExceptions in an ExceptionGroupzCannot nest BaseExceptions in )r,   r;   r0   typer   
ValueError	enumerater   r   r.   r   r(   r>   __name__super__new__r-   _exceptions)r!   r<   r=   ir   instancer    r"   r#   rD   C   s:    







zBaseExceptionGroup.__new__objectNone)r<   r=   argsr   c                 G  s   t j| ||f|  d S r'   )r   __init__)r9   r<   r=   rK   r"   r"   r#   rL   k   s    zBaseExceptionGroup.__init__)noter   c                 C  sF   t |ts&td|dt|j dt| ds6g | _| j| d S )NzExpected a string, got note=z (type )r2   )r,   r;   r0   r?   rB   r7   r2   append)r9   rM   r"   r"   r#   add_notes   s    

zBaseExceptionGroup.add_noter   c                 C  s
   | j d S )Nr   )rK   r9   r"   r"   r#   message~   s    zBaseExceptionGroup.messagezGtuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]c                 C  s
   t | jS r'   )r-   rE   rR   r"   r"   r#   
exceptions   s    zBaseExceptionGroup.exceptions1type[_ExceptionT] | tuple[type[_ExceptionT], ...]"ExceptionGroup[_ExceptionT] | None)_BaseExceptionGroup__conditionr   c                 C  s   d S r'   r"   r9   rW   r"   r"   r#   subgroup   s    zBaseExceptionGroup.subgroupz9type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]z*BaseExceptionGroup[_BaseExceptionT] | Nonec                 C  s   d S r'   r"   rX   r"   r"   r#   rY      s    z>Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], bool]z-BaseExceptionGroup[_BaseExceptionT_co] | Nonec                 C  s   d S r'   r"   rX   r"   r"   r#   rY      s    zztype[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], bool]c                 C  s   t |}d}|| r| S g }| jD ]P}t|trZ||}|d k	rL|| ||k	rrd}q"||rn|| q"d}q"|s|| S |rt| |}|S d S d S )NFT)r1   rT   r,   r   rY   rO   r:   )r9   rW   r&   ZmodifiedrT   r   rY   groupr"   r"   r#   rY      s*    




zXtuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r'   r"   rX   r"   r"   r#   split   s    zBaseExceptionGroup.splitz`tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r'   r"   rX   r"   r"   r#   r[      s    zctuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r'   r"   rX   r"   r"   r#   r[      s    r%   a!  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 ]`}t|trh||\}}|d k	rT|| |d k	r|| q&||r||| q&|| q&d }|rt| |}d }	|rt| |}	||	fS r'   )r1   rT   r,   r   r[   rO   r:   )
r9   rW   r&   Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr"   r"   r#   r[      s2    



 zSequence[_ExceptionT]zExceptionGroup[_ExceptionT])_BaseExceptionGroup__excsr   c                 C  s   d S r'   r"   r9   r\   r"   r"   r#   r3     s    zBaseExceptionGroup.derivezSequence[_BaseExceptionT]z#BaseExceptionGroup[_BaseExceptionT]c                 C  s   d S r'   r"   r]   r"   r"   r#   r3     s    c                 C  s   t | j|S r'   )r   rS   r]   r"   r"   r#   r3     s    c                 C  s4   t | jdkrdnd}| j dt | j d| dS )N    sz (z sub-exceptionrN   )lenrE   rS   )r9   suffixr"   r"   r#   __str__  s    zBaseExceptionGroup.__str__c                 C  s&   | j j d| jd d| jd dS )N(r   z, r^   rN   )r    rB   rK   rR   r"   r"   r#   __repr__  s    zBaseExceptionGroup.__repr__)rB   
__module____qualname____doc__rD   rL   rP   propertyrS   rT   r   rY   r[   r3   rc   re   __classcell__r"   r"   rH   r#   r   @   s:   (!2c                      s   e Zd Zddddd fddZeredd	d
dZedddddZedddddZddd fddZedddddZ	edddddZ	dddd fddZ	  Z
S )r   ztype[_ExceptionGroupSelf]r;   zSequence[_ExceptionT_co]r   )r!   _ExceptionGroup__message_ExceptionGroup__exceptionsr   c                   s   t  | ||S r'   )rC   rD   )r!   rk   rl   rH   r"   r#   rD     s    zExceptionGroup.__new__z;tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]rQ   c                 C  s   d S r'   r"   rR   r"   r"   r#   rT   #  s    zExceptionGroup.exceptionsrU   rV   )_ExceptionGroup__conditionr   c                 C  s   d S r'   r"   r9   rm   r"   r"   r#   rY   (  s    zExceptionGroup.subgroupz6Callable[[_ExceptionT_co | _ExceptionGroupSelf], bool]z%ExceptionGroup[_ExceptionT_co] | Nonec                 C  s   d S r'   r"   rn   r"   r"   r#   rY   -  s    zTtype[_ExceptionT] | tuple[type[_ExceptionT], ...] | Callable[[_ExceptionT_co], bool]c                   s   t  |S r'   )rC   rY   rn   rH   r"   r#   rY   2  s    zPtuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  s   d S r'   r"   rn   r"   r"   r#   r[   :  s    zExceptionGroup.splitzStuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  s   d S r'   r"   rn   r"   r"   r#   r[   A  s    )r9   rm   r   c                   s   t  |S r'   )rC   r[   rn   rH   r"   r#   r[   H  s    )rB   rf   rg   rD   r   ri   rT   r   rY   r[   rj   r"   r"   rH   r#   r     s   )!Z
__future__r   sysZcollections.abcr   r   	functoolsr   inspectr   r   typingr   r	   r
   r   r   r   version_infoZtyping_extensionsr   r   r   r>   r   r   r   r   r$   r1   r:   r   r   r"   r"   r"   r#   <module>   s:    
      
 Z