7ec@sdZddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z dZ dejfdYZd 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|tjo(|jdjtjkS(Ni(t isinstanceRtNodetchildrenttypeRtSTRING(tstmt((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyt is_docstringstFixTupleParamscBs,eZdZeZdZdZdZRS(is funcdef< 'def' any parameters< '(' args=any ')' > ['->' any] ':' suite=any+ > | lambda= lambdef< 'lambda' args=vfpdef< '(' inner=any ')' > ':' body=any > c s0d|krj||Sg|d}|d}|djdjtjkryd}|djdj}tn!d}d}tjtjdt fd }|jt j kr||n`|jt j kr1xKt |jD]7\}} | jt j kr|| d |dkqqWns;dSxD]} |d| _qBW|} |dkr{d d_n1t|dj|r|d_|d} nxD]} |d| _qW|dj| | +x=t| d| tdD]}||dj|_qW|djdS( Ntlambdatsuitetargsiiiu; ucstj}|j}d|_t||j}|rNd|_n|j|jtjt j |jgdS(Nuu ( Rtnew_nametclonetprefixRtreplacetappendRR Rt simple_stmt(t tuple_argt add_prefixtntargR(tendt new_linestself(s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyt handle_tupleCs    Ru (ttransform_lambdaR R RtINDENTtvalueRRtLeaftFalseRttfpdeft typedargslistt enumeratetparentRRtrangetlentchanged( R tnodetresultsRRtstarttindentR!tiRtlinetafter((RRR s6/usr/lib64/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| jx|j D]} | jtjkr| j |krg|| j D]} | j^q} tjtj| jg| } | j| _| j| qqWdS(NRtbodytinneru R(t simplify_argsR RtNAMERRRt find_paramst map_to_indexRt tuple_nameRt post_orderR$RR Rtpower(R R.R/RR6R7tparamstto_indexttup_namet new_paramRtct subscriptstnew((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR"ns(       !&  (t__name__t __module__t run_ordertTruet BM_compatibletPATTERNR5R"(((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyRs   @cCso|jtjtjfkr|S|jtjkr[x#|jtjkrV|jd}q4W|Std|dS(NisReceived unexpected node %s(R RtvfplistRR9tvfpdefR t RuntimeError(R.((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR8scCsn|jtjkr#t|jdS|jtjkr<|jSg|jD]$}|jtjkrFt|^qFS(Ni( R RRMR:R RR9R$tCOMMA(R.RC((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR:s cCs|dkri}nxht|D]Z\}}ttt|g}t|trnt||d|q"||||s. l