�`^c@s�dZddlmZddlmZddlmZddlmZmZm Z m
Z
mZmZd�Z
dejfd��YZd �Zd
�Zgd
d�Zd�Zd
S(s:Fixer for function definitions with tuple parameters.
def func(((a, b), c), d):
...
->
def func(x, d):
((a, b), c) = x
...
It will also support lambdas:
lambda (x, y): x + y -> lambda t: t[0] + t[1]
# The parens are a syntax error in Python 3
lambda (x): x + y -> lambda x: x + y
i(tpytree(ttoken(t
fixer_base(tAssigntNametNewlinetNumbert SubscripttsymscCs)t|tj�o(|jdjtjkS(Ni(t
isinstanceRtNodetchildrenttypeRtSTRING(tstmt((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pytis_docstringstFixTupleParamscBs,eZdZeZdZd�Zd�ZRS(is
funcdef< 'def' any parameters< '(' args=any ')' >
['->' any] ':' suite=any+ >
|
lambda=
lambdef< 'lambda' args=vfpdef< '(' inner=any ')' >
':' body=any
>
cs0d|kr�j||�Sg�|d}|d}|djdjtjkryd}|djdj}t��n!d}d}tjtjd��t ���fd �}|jt
jkr�||�n`|jt
jkr1xKt
|j�D]7\}} | jt
jkr�| d
|dk�q�Wn�s;dSx�D]}
|d|
_qBW|}|dkr{d�d_n1t|dj|�r�|�d_|d}nx�D]}
|d|
_q�W�|dj||+x=t|d|t��d�D]}||dj|_qW|dj�dS(Ntlambdatsuitetargsiiiu; ucs�t�j��}|j�}d|_t||j��}|rNd|_n|j|��jtjt j
|�j�g��dS(Nuu (Rtnew_nametclonetprefixRtreplacetappendRR
Rtsimple_stmt(t tuple_argt
add_prefixtntargR(tendt new_linestself(s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pythandle_tupleCs
Ru (ttransform_lambdaRRRtINDENTtvalueRRtLeaftFalseRttfpdeft
typedargslistt enumeratetparentRRtrangetlentchanged(R tnodetresultsRRtstarttindentR!tiRtlinetafter((RRR s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyt transform.sF
(cCsN|d}|d}t|d�}|jtjkr\|j�}d|_|j|�dSt|�}t|�}|j t
|��}t|dd�} |j| j��x�|j�D]�}
|
jtjkr�|
j
|kr�g||
j
D]}|j�^q�tjtj| j�g|�}
|
j|
_|
j|
�q�q�WdS(NRtbodytinneru R(t
simplify_argsRRtNAMERRRtfind_paramstmap_to_indexRt
tuple_nameRt
post_orderR$RR
Rtpower(R R.R/RR6R7tparamstto_indexttup_namet new_paramRtct
subscriptstnew((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyR"ns(
!&(t__name__t
__module__t run_ordertTruet
BM_compatibletPATTERNR5R"(((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyRs
@cCso|jtjtjfkr|S|jtjkr[x#|jtjkrV|jd}q4W|Std|��dS(NisReceived unexpected node %s(RRtvfplistRR9tvfpdefRtRuntimeError(R.((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyR8�scCsn|jtjkr#t|jd�S|jtjkr<|jSg|jD]$}|jtjkrFt|�^qFS(Ni( RRRMR:RRR9R$tCOMMA(R.RC((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyR:�s
cCs�|dkri}nxht|�D]Z\}}ttt|���g}t|t�rnt||d|�q"||||<q"W|S(Ntd(tNoneR)RRtunicodeR tlistR;(t
param_listRRPR2tobjttrailer((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyR;�s cCsVg}x@|D]8}t|t�r8|jt|��q
|j|�q
Wdj|�S(Nu_(R RSRR<tjoin(RTtlRU((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyR<�s
N(t__doc__tRtpgen2RRt
fixer_utilRRRRRRRtBaseFixRR8R:RQR;R<(((s4/sys/lib/python2.7/lib2to3/fixes/fix_tuple_params.pyt<module>s. l
|