B
    	Q˜[w  ã               @   sJ   d Z ddlmZmZ ddlmZ ddlmZmZm	Z	 G dd„ dej
ƒZdS )aè  Fixer for 'raise E, V'

From Armin Ronacher's ``python-modernize``.

raise         -> raise
raise E       -> raise E
raise E, V    -> raise E(V)

raise (((E, E'), E''), E'''), V -> raise E(V)


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Ú
fixer_base)Útoken)ÚNameÚCallÚis_tuplec               @   s   e Zd ZdZdZdd„ ZdS )ÚFixRaiseTz5
    raise_stmt< 'raise' exc=any [',' val=any] >
    c       	      C   sè   | j }|d  ¡ }|jtjkr2d}|  ||¡ d S t|ƒrbx t|ƒrZ|jd jd  ¡ }q<W d|_d|krŒt	 
|jtdƒ|g¡}|j|_|S |d  ¡ }t|ƒrºdd	„ |jdd
… D ƒ}nd|_|g}t	j
|jtdƒt||ƒg|jdS )NÚexcz+Python 3 does not support string exceptionsé   r   ú ÚvalÚraisec             S   s   g | ]}|  ¡ ‘qS © )Úclone)Ú.0Úcr   r   ú:lib/python3.7/site-packages/libfuturize/fixes/fix_raise.pyú
<listcomp>B   s    z&FixRaise.transform.<locals>.<listcomp>éÿÿÿÿÚ )Úprefix)Úsymsr   Útyper   ÚSTRINGZcannot_convertr   Zchildrenr   r   ZNodeZ
raise_stmtr   r   )	ÚselfZnodeZresultsr   r	   ÚmsgÚnewr   Úargsr   r   r   Ú	transform$   s,    
zFixRaise.transformN)Ú__name__Ú
__module__Ú__qualname__ZBM_compatibleZPATTERNr   r   r   r   r   r      s   r   N)Ú__doc__Zlib2to3r   r   Zlib2to3.pgen2r   Zlib2to3.fixer_utilr   r   r   ZBaseFixr   r   r   r   r   Ú<module>   s   