o
    US`c5                     @  s   d dl mZ d dl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mZ edddZed	edZed
edZeee eee df eegef f ZdddZdddZG dd deee ZG dd dee eee ZdS )    )annotations)Sequence)partial)getmroisclass)AnyCallableGenericTupleTypeTypeVarUnioncastTBaseExceptionGroup)boundEBaseE.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   E/usr/local/lib/python3.10/dist-packages/exceptiongroup/_exceptions.pycheck_direct_subclass   s
   r   	condition_SplitConditionCallable[[BaseException], bool]c                 C  s~   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
| r;tttgtf | 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?expected a function, exception type or tuple of exception types)r   r$   r   r   r   r   r   
isinstancetupleallcallabler   r   	TypeError)r    r   r   r   get_condition_filter   s   

r-   c                      s   e Zd ZdZd( fdd	Zd) fddZd*ddZed+ddZed,ddZ	d-ddZ
d.dd Zd/d"d#Zd+d$d%Zd+d&d'Z  ZS )0r   z/A combination of multiple unrelated exceptions._BaseExceptionGroup__messagestr_BaseExceptionGroup__exceptionsSequence[EBase]r   -BaseExceptionGroup[EBase] | ExceptionGroup[E]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 | ||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'   @   s    z-BaseExceptionGroup.__new__.<locals>.<genexpr>)r(   r/   r,   typer   
ValueError	enumerater   r   r*   ExceptionGroupsuper__new__)r   r.   r0   ir   r   r   r   r9   -   s$   



zBaseExceptionGroup.__new__argsr   c                   s&   t  j||g|R   || _|| _d S r#   )r8   __init___message_exceptions)selfr.   r0   r<   r;   r   r   r=   E   s   
zBaseExceptionGroup.__init__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(   r/   r,   r4   __name__hasattrrD   append)r@   rA   r   r   r   add_noteJ   s   

zBaseExceptionGroup.add_notec                 C  s   | j S r#   )r>   r@   r   r   r   messageU   s   zBaseExceptionGroup.messagetuple[EBase, ...]c                 C  s
   t | jS r#   )r)   r?   rI   r   r   r   
exceptionsY   s   
zBaseExceptionGroup.exceptionsr@   r   _BaseExceptionGroup__condition_SplitCondition[EBase]T | Nonec                 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   subgrouprG   derive	__cause____context____traceback__)r@   rM   r    modifiedrL   r   rP   groupr   r   r   rP   ]   s2   




zBaseExceptionGroup.subgrouptuple[T | None, T | 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   splitrG   rQ   rR   rS   rT   )
r@   rM   r    Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr   r   r   rX   |   s:   





zBaseExceptionGroup.split_BaseExceptionGroup__excsc                 C  s&   t | j|}t| drt| j|_|S )NrD   )r   rJ   rF   listrD   )r@   rY   egr   r   r   rQ      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-exceptionrC   )lenr?   rJ   )r@   suffixr   r   r   __str__   s   zBaseExceptionGroup.__str__c                 C  s   | j j d| jd| jdS )N(z, rC   )r   rE   rJ   r?   rI   r   r   r   __repr__   s   zBaseExceptionGroup.__repr__)r.   r/   r0   r1   r   r2   )r.   r/   r0   r1   r<   r   )rA   r/   r   rB   )r   r/   )r   rK   )r@   r   rM   rN   r   rO   )r@   r   rM   rN   r   rW   )r@   r   rY   r1   r   r   )rE   
__module____qualname____doc__r9   r=   rH   propertyrJ   rL   rP   rX   rQ   ra   rc   __classcell__r   r   r;   r   r   *   s    



&
c                      s   e Zd Zd	 fddZ  ZS )
r7   _ExceptionGroup__messager/   _ExceptionGroup__exceptionsSequence[E]r   ExceptionGroup[E]c                   s8   t  | ||}| tu r|D ]}t|tstdq|S )Nz/Cannot nest BaseExceptions in an ExceptionGroup)r8   r9   r7   r(   r3   r,   )r   ri   rj   instancer   r;   r   r   r9      s   
zExceptionGroup.__new__)ri   r/   rj   rk   r   rl   )rE   rd   re   r9   rh   r   r   r;   r   r7      s    r7   N)r   r   r   r   r   r   )r    r!   r   r"   )
__future__r   collections.abcr   	functoolsr   inspectr   r   typingr   r   r	   r
   r   r   r   r   r   r   r   r3   r   r   r!   r   r-   r   r7   r   r   r   r   <module>   s&    (


  