
    ;en                     p    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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                       e Zd ZdZdZd ZdS )FixRaiseTzB
    raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
    c                 h   | j         }|d                                         }|j        t          j        k    rd}|                     ||           d S t          |          rOt          |          r9|j        d         j        d                                         }t          |          9d|_        d|vr7t          j
        |j        t          d          |g          }|j        |_        |S |d                                         }t          |          r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z   }t          j
        |j        t          d          g|z             }|j        |_        |S t          j
        |j        t          d          t          ||          g|j                  S )Nexcz+Python 3 does not support string exceptions        valraisec                 6    g | ]}|                                 S  )clone).0cs     ./usr/lib/python3.11/lib2to3/fixes/fix_raise.py
<listcomp>z&FixRaise.transform.<locals>.<listcomp>D   s     :::!AGGII:::     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_tbs               r   	transformzFixRaise.transform&   s   yen""$$8u|##?Cc***F C== 	3-- : l1o.q17799 3-- : CJ+doWs/CDDCCJJen""$$C== 	::s|AbD'9:::DDCJ5D7??$$&&BBIA x5:%%f)<)<dOO1d#34455"GG+d.g'0IJJCCJJ;t $WtC?&*k3 3 3 3r   N)__name__
__module____qualname__BM_compatiblePATTERNr4   r   r   r   r   r      s/        MG43 43 43 43 43r   r   N)__doc__r   r   pgen2r   r   
fixer_utilr   r   r   r	   r
   BaseFixr   r   r   r   <module>r>      s    2                   < < < < < < < < < < < < < <;3 ;3 ;3 ;3 ;3z! ;3 ;3 ;3 ;3 ;3r   