o
    Š�bcn  ã                   @   sZ   d Z ddlmZ ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ G dd„ dejƒZdS )	a[  Fixer for 'raise E, V, T'

raise         -> raise
raise E       -> raise E
raise E, V    -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)

raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T               -> warns about string exceptions


CAVEATS:
1) "raise E, V" will be incorrectly translated if V is an exception
   instance. The correct Python 3 idiom is

        raise E from V

   but since we can't detect instance-hood by syntax alone and since
   any client code would have to be changed as well, we don't automate
   this.
é   )Úpytree)Útoken)Ú
fixer_base)ÚNameÚCallÚAttrÚArgListÚis_tuplec                   @   s   e Zd ZdZdZdd„ ZdS )ÚFixRaiseTzB
    raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
    c                 C   sf  | j }|d  ¡ }|jtjkrd}|  ||¡ d S t|ƒr2t|ƒr/|jd jd  ¡ }t|ƒs!d|_d|vrGt	 
|jtdƒ|g¡}|j|_|S |d  ¡ }t|ƒr^dd	„ |jdd
… D ƒ}nd|_|g}d|v r¢|d  ¡ }	d|	_|}
|jtjks~|jdkrƒt||ƒ}
t|
tdƒƒt|	gƒg }t	 
|jtdƒg| ¡}|j|_|S t	j
|jtdƒt||ƒg|jd�S )NÚexcz+Python 3 does not support string exceptionsé   é    ú ÚvalÚraisec                 S   s   g | ]}|  ¡ ‘qS © )Úclone)Ú.0Úcr   r   ú./usr/lib/python3.10/lib2to3/fixes/fix_raise.pyÚ
<listcomp>D   s    z&FixRaise.transform.<locals>.<listcomp>éÿÿÿÿÚ ÚtbÚNoneÚwith_traceback)Úprefix)Úsymsr   Útyper   ÚSTRINGÚcannot_convertr	   Úchildrenr   r   ÚNodeÚ
raise_stmtr   ÚNAMEÚvaluer   r   r   Úsimple_stmt)ÚselfÚnodeÚresultsr   r   ÚmsgÚnewr   Úargsr   ÚeÚwith_tbr   r   r   Ú	transform&   sD   ý
þzFixRaise.transformN)Ú__name__Ú
__module__Ú__qualname__ÚBM_compatibleÚPATTERNr/   r   r   r   r   r
      s    r
   N)Ú__doc__r   r   Úpgen2r   r   Ú
fixer_utilr   r   r   r   r	   ÚBaseFixr
   r   r   r   r   Ú<module>   s    