o
    i,                     @  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 r;d 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Z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)bound	covariantdefault_BaseExceptionT)r   _ExceptionT_co_ExceptionT_ExceptionGroupSelfExceptionGroup_BaseExceptionGroupSelfBaseExceptionGroup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$   T/home/kim/smarthome/.venv/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   


r4   c                 C  s<   |  |}| j|_| j|_| j|_t| drt| j|_|S )N	__notes__)derive	__cause____context____traceback__hasattrlistr5   )selfZexcsegr$   r$   r%   _derive_and_copy_attributes5   s   

r>   c                      s   e Zd ZdZd= fd
dZd>ddZd?ddZed@ddZedAddZ	e
dBddZe
dCd dZe
dDd#dZdEd%dZe
dFd'd(Ze
dGd*d(Ze
dHd,d(ZdId/d(Ze
dJd3d4Ze
dKd7d4ZdKd8d4Zd@d9d:Zd@d;d<Z  ZS )Lr   z/A combination of multiple unrelated exceptions.r#   type[_BaseExceptionGroupSelf]_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 | ||}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/   rA   r3   typer   
ValueError	enumerater   r   r1   r   r+   rD   __name__super__new__r0   _exceptions)r#   r@   rB   ir   instancer"   r$   r%   rJ   C   s>   








zBaseExceptionGroup.__new__argsobjectNonec                 G  s   t j| ||g|R   d S r*   )r   __init__)r<   r@   rB   rO   r$   r$   r%   rR   k   s   zBaseExceptionGroup.__init__notec                 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 )r5   )r/   rA   r3   rE   rH   r:   r5   append)r<   rS   r$   r$   r%   add_notes   s   

zBaseExceptionGroup.add_notec                 C  s
   | j d S )Nr   )rO   r<   r$   r$   r%   message~   s   
zBaseExceptionGroup.messageGtuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]c                 C  s
   t | jS r*   )r0   rK   rW   r$   r$   r%   
exceptions   s   
zBaseExceptionGroup.exceptions_BaseExceptionGroup__condition1type[_ExceptionT] | tuple[type[_ExceptionT], ...]"ExceptionGroup[_ExceptionT] | Nonec                 C     d S r*   r$   r<   r[   r$   r$   r%   subgroup      zBaseExceptionGroup.subgroup9type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]*BaseExceptionGroup[_BaseExceptionT] | Nonec                 C  r^   r*   r$   r_   r$   r$   r%   r`      ra   >Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], bool]-BaseExceptionGroup[_BaseExceptionT_co] | Nonec                 C  r^   r*   r$   r_   r$   r$   r%   r`      s   ztype[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], 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 |rGt| |}|S d S )NFT)r4   rZ   r/   r   r`   rU   r>   )r<   r[   r'   modifiedrZ   r   r`   groupr$   r$   r%   r`      s,   




Xtuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  r^   r*   r$   r_   r$   r$   r%   split      zBaseExceptionGroup.split`tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  r^   r*   r$   r_   r$   r$   r%   rj      rk   ctuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  r^   r*   r$   r_   r$   r$   r%   rj      s   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 }|rMt| |}d }	|rVt| |}	||	fS r*   )r4   rZ   r/   r   rj   rU   r>   )
r<   r[   r'   Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr$   r$   r%   rj      s2   




_BaseExceptionGroup__excsSequence[_ExceptionT]ExceptionGroup[_ExceptionT]c                 C  r^   r*   r$   r<   ro   r$   r$   r%   r6     s   zBaseExceptionGroup.deriveSequence[_BaseExceptionT]#BaseExceptionGroup[_BaseExceptionT]c                 C  r^   r*   r$   rr   r$   r$   r%   r6     ra   c                 C  s   t | j|S r*   )r   rX   rr   r$   r$   r%   r6     s   c                 C  s4   t | jdkr	dnd}| j dt | j d| dS )N    sz (z sub-exceptionrT   )lenrK   rX   )r<   suffixr$   r$   r%   __str__  s   zBaseExceptionGroup.__str__c                 C  s&   | j j d| jd d| jd dS )N(r   z, ru   rT   )r"   rH   rO   rW   r$   r$   r%   __repr__  s   &zBaseExceptionGroup.__repr__)r#   r?   r@   rA   rB   rC   r   r   )r@   rA   rB   rC   rO   rP   r   rQ   )rS   rA   r   rQ   )r   rA   )r   rY   )r[   r\   r   r]   )r[   rb   r   rc   )r[   rd   r   re   )r[   rf   r   rc   )r[   r\   r   ri   )r[   rb   r   rl   )r[   rd   r   rm   )r[   r(   r   rn   )ro   rp   r   rq   )ro   rs   r   rt   )rH   
__module____qualname____doc__rJ   rR   rV   propertyrX   rZ   r   r`   rj   r6   rz   r|   __classcell__r$   r$   rN   r%   r   @   s<    
(

!
2

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 )'r   r#   type[_ExceptionGroupSelf]_ExceptionGroup__messagerA   _ExceptionGroup__exceptionsSequence[_ExceptionT_co]r   r   c                   s   t  | ||S r*   )rI   rJ   )r#   r   r   rN   r$   r%   rJ     s   zExceptionGroup.__new__;tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]c                 C  r^   r*   r$   rW   r$   r$   r%   rZ   #  ra   zExceptionGroup.exceptions_ExceptionGroup__conditionr\   r]   c                 C  r^   r*   r$   r<   r   r$   r$   r%   r`   (  ra   zExceptionGroup.subgroup6Callable[[_ExceptionT_co | _ExceptionGroupSelf], bool]%ExceptionGroup[_ExceptionT_co] | Nonec                 C  r^   r*   r$   r   r$   r$   r%   r`   -  ra   Ttype[_ExceptionT] | tuple[type[_ExceptionT], ...] | Callable[[_ExceptionT_co], bool]c                      t  |S r*   )rI   r`   r   rN   r$   r%   r`   2  s   Ptuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  r^   r*   r$   r   r$   r$   r%   rj   :     zExceptionGroup.splitStuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  r^   r*   r$   r   r$   r$   r%   rj   A  r   r<   c                   r   r*   )rI   rj   r   rN   r$   r%   rj   H  s   )r#   r   r   rA   r   r   r   r   )r   r   )r   r\   r   r]   )r   r   r   r   )r   r   r   r]   )r   r\   r   r   )r   r   r   r   )r<   r   r   r   r   r   )rH   r}   r~   rJ   r   r   rZ   r   r`   rj   r   r$   r$   rN   r%   r     s     )r   r   r   r   r   r    )r'   r(   r   r)   )!
__future__r   syscollections.abcr   r   	functoolsr   inspectr   r   typingr   r	   r
   r   r   r   version_infoZtyping_extensionsr   r   r   rD   r   r   r   r   r&   r4   r>   r   r   r$   r$   r$   r%   <module>   s0     



 Z