B
    sc%                 @  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mZ erld 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dddZdd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AnyGenericTypeTypeVarcastoverload)Self_BaseExceptionT_coT)boundZ	covariant_BaseExceptionT)r   _ExceptionT_co_ExceptionTBaseExceptionztuple[type[BaseException]]bool)excparentsreturnc             C  s,   x&t | jd d D ]}||krdS qW dS )NTF)r   	__class__)r   r   cls r   9lib/python3.7/site-packages/exceptiongroup/_exceptions.pycheck_direct_subclass   s    r   z`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    


r*   c                  s  e Zd ZdZdddd fddZdddd	 f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dZddd dd!dZe
ddd"dd#d$Ze
ddd%dd&d$Zddd'dd(d$Zdddd)d*d+Zddd,d-Zddd.d/Z  ZS )0BaseExceptionGroupz/A combination of multiple unrelated exceptions.strzSequence[_BaseExceptionT_co]r   )_BaseExceptionGroup__message_BaseExceptionGroup__exceptionsr   c               s   t |tstdt| t |ts.td|s:tdx.t|D ]"\}}t |tsDtd| dqDW | tkrt	dd |D rt
} 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 )N)r%   	Exception)r"   r   r   r   r   r$   C   s    z-BaseExceptionGroup.__new__.<locals>.<genexpr>)r%   r,   r)   typer   
ValueError	enumerater   r+   r'   ExceptionGroupsuper__new__)r   r-   r.   ir   )r   r   r   r5   0   s    


zBaseExceptionGroup.__new__r	   )r-   r.   argsc               s$   t  j||f|  || _|| _d S )N)r4   __init___message_exceptions)selfr-   r.   r7   )r   r   r   r8   H   s    zBaseExceptionGroup.__init__None)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 )	__notes__)r%   r,   r)   r0   __name__hasattrr?   append)r;   r=   r   r   r   add_noteO   s    

zBaseExceptionGroup.add_note)r   c             C  s   | j S )N)r9   )r;   r   r   r   messageZ   s    zBaseExceptionGroup.messagezGtuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]c             C  s
   t | jS )N)r&   r:   )r;   r   r   r   
exceptions^   s    zBaseExceptionGroup.exceptionsz9type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]z*BaseExceptionGroup[_BaseExceptionT] | None)_BaseExceptionGroup__conditionr   c             C  s   d S )Nr   )r;   rF   r   r   r   subgroupd   s    zBaseExceptionGroup.subgroupz$Callable[[_BaseExceptionT_co], bool]zSelf | None)r;   rF   r   c             C  s   d S )Nr   )r;   rF   r   r   r   rG   j   s    z`type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co], bool]z1BaseExceptionGroup[_BaseExceptionT] | Self | Nonec             C  s   t |}d}|| r| S g }xZ| jD ]P}t|tr\||}|d k	rN|| ||k	rtd}q$||rp|| q$d}q$W |s| S |r| |}| j|_| j|_| j	|_	|S d S d S )NFT)
r*   rE   r%   r+   rG   rB   derive	__cause____context____traceback__)r;   rF   r    ZmodifiedrE   r   rG   groupr   r   r   rG   p   s0    



z>tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]c             C  s   d S )Nr   )r;   rF   r   r   r   split   s    zBaseExceptionGroup.splitztuple[Self | None, Self | None]c             C  s   d S )Nr   )r;   rF   r   r   r   rM      s    z`tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None] | tuple[Self | None, Self | None]c       
      C  s   t |}|| r| d fS g }g }xj| jD ]`}t|trj||\}}|d k	rV|| |d k	r|| q(||r~|| q(|| q(W d }|r| |}| j|_| j|_| j	|_	d }	|r| |}	| j|	_| j|	_| j	|	_	||	fS )N)
r*   rE   r%   r+   rM   rB   rH   rI   rJ   rK   )
r;   rF   r    Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr   r   r   rM      s8    



)r;   _BaseExceptionGroup__excsr   c             C  s&   t | j|}t| dr"t| j|_|S )Nr?   )r+   rD   rA   listr?   )r;   rN   Zegr   r   r   rH      s    
zBaseExceptionGroup.derivec             C  s4   t | jdkrdnd}| j dt | j d| dS )N    sz (z sub-exceptionr>   )lenr:   rD   )r;   suffixr   r   r   __str__   s    zBaseExceptionGroup.__str__c             C  s   | j j d| jd| jdS )N(z, r>   )r   r@   rD   r:   )r;   r   r   r   __repr__   s    zBaseExceptionGroup.__repr__)r@   
__module____qualname____doc__r5   r8   rC   propertyrD   rE   r   rG   rM   rH   rU   rW   __classcell__r   r   )r   r   r+   -   s   $+r+   c                  s   e Zd Z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dZdddd fddZeddddddZ	eddddddZ	dddd fddZ	  Z
S )r3   r,   zSequence[_ExceptionT_co]r   )_ExceptionGroup__message_ExceptionGroup__exceptionsr   c               s<   t  | ||}| tkr8x|D ]}t|tstdqW |S )Nz/Cannot nest BaseExceptions in an ExceptionGroup)r4   r5   r3   r%   r/   r)   )r   r]   r^   instancer   )r   r   r   r5      s    


zExceptionGroup.__new__z;tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...])r   c             C  s   d S )Nr   )r;   r   r   r   rE      s    zExceptionGroup.exceptionsz1type[_ExceptionT] | tuple[type[_ExceptionT], ...]z"ExceptionGroup[_ExceptionT] | None)_ExceptionGroup__conditionr   c             C  s   d S )Nr   )r;   r`   r   r   r   rG      s    zExceptionGroup.subgroupz Callable[[_ExceptionT_co], bool]zSelf | None)r;   r`   r   c             C  s   d S )Nr   )r;   r`   r   r   r   rG      s    zTtype[_ExceptionT] | tuple[type[_ExceptionT], ...] | Callable[[_ExceptionT_co], bool]z)ExceptionGroup[_ExceptionT] | Self | Nonec               s   t  |S )N)r4   rG   )r;   r`   )r   r   r   rG      s    z6tuple[ExceptionGroup[_ExceptionT] | None, Self | None]c             C  s   d S )Nr   )r;   r`   r   r   r   rM     s    zExceptionGroup.splitztuple[Self | None, Self | None]c             C  s   d S )Nr   )r;   r`   r   r   r   rM   
  s    zXtuple[ExceptionGroup[_ExceptionT] | None, Self | None] | tuple[Self | None, Self | None]c               s   t  |S )N)r4   rM   )r;   r`   )r   r   r   rM     s    )r@   rX   rY   r5   r   r[   rE   r   rG   rM   r\   r   r   )r   r   r3      s   r3   N)Z
__future__r   Zcollections.abcr   r   	functoolsr   inspectr   r   typingr   r	   r
   r   r   r   r   r   r   r   r   r/   r   r   r   r*   r+   r3   r   r   r   r   <module>   s   $
 0